<jupyter_start><jupyter_text>```<jupyter_code>y_train = np.reshape(y_train, (339,1))
y_test = np.reshape(y_test,(167,1))
X_train_new = X_train[:,6:7]
X_test_new = X_test[:,6:7]<jupyter_output><empty_output><jupyter_text>Data visualization<jupyter_code>plt.scatter(X_train_new,y_train)
reg = LinearRegression().fit(X_train_new,y_train)
reg.score(X_test_new,y_test)
y_pred = reg.predict(X_test_new)

metrics.mean_squared_error(y_test,y_pred)
reg.coef_
reg.intercept_
def plot_lin(X,y,slope,c):
    
    fig = plt.figure(figsize=(10,5))
    ax = fig.add_subplot(111)
    ax.scatter(X,y,label='Data')
    plt.plot(X,X*slope + c,label = 'line', color = 'g')
    ax.legend()
    plt.show()
X = X_train_new
y = y_train
slope = reg.coef_
c = reg.intercept_
plot_lin(X,y,slope,c)
import pymc3 as pm
X = X_train_new
with pm.Model() as model: 
    sigma = pm.HalfCauchy('sigma', beta=10, testval=1.)
    intercept = pm.Normal('Intercept', 0, sd=20)
    x_coeff = pm.Normal('x', 0, sd=20)

    # Define likelihood
    likelihood = pm.Normal('y', mu=intercept + x_coeff * X,
                        sd=sigma, observed=y_train)

    # Inference!
    trace = pm.sample(15000,chains =1,cores=4)
pm.traceplot(trace)
plt.show()
#print(np.mean([1 if obj<0 else 0 for obj in trace['x']]))
print(np.mean([1 if obj<(31.2) else 0 for obj in trace[intercept]]))
X_train_new

y.shape<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup