<jupyter_start><jupyter_text>Since data has few data points, train_test_split is not done and entire data is used for training the model<jupyter_code>X = restaurant_data.Student_Population.values.reshape(-1,1)
y = restaurant_data.Sales.values.reshape(-1,1)
# X_train,X_test,y_train,y_test = train_test_split(X,y,test_size = 0.2,random_state = 88)
reg = LinearRegression()
model = reg.fit(X,y)
print(f'Y intercept for linear regression: {model.intercept_}')
print(f'Slope for linear regression: {model.coef_}')
model
y_pred = model.predict(X)
fig,axes = plt.subplots()
axes.scatter(restaurant_data['Student_Population'],restaurant_data.Sales, color = 'green')
axes.plot(X,y_pred,color = 'blue')
axes.set(ylabel = 'Quarterly Sales (In Thousand Dollars)',xlabel = 'Student Population (In Thousands)')<jupyter_output><empty_output><jupyter_text>**Note:** The point estimate of an individual value of y is the **same** as the point estimate for the mean value of y.Thus, the **predicted quarterly sales for an individual restaurant with 10,000 students = estimated mean quarterly sales of all restaurants with 10,000 students = 110,000 dollars**<jupyter_code>reg.predict([[10]])
import seaborn as sns
# Another way of plotting regression lines
x = restaurant_data['Student_Population']
y = restaurant_data['Sales']
sns.regplot(x,y,fit_reg=True)
plt.scatter(np.mean(x),np.mean(y),color = 'green')<jupyter_output>C:\Anaconda\lib\site-packages\seaborn\_decorators.py:36: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  warnings.warn(<jupyter_text>The shaded area represents the **estimated confidence interval for the mean value of y i.e. E(y) for the corresponding x value**.  Prediction Interval<jupyter_code>from statsmodels.stats.outliers_influence import summary_table<jupyter_output><empty_output><jupyter_text>**Note:**  * OLS(All caps) located inside 's' is used for summary table and confidence interval estimation * ols(all small) located inside 'sm' is used for ANOVA and Residual Analysis<jupyter_code>y = restaurant_data['Sales']
X = s.add_constant(restaurant_data['Student_Population'])
model1 = s.OLS(y,X).fit()
model1.summary()
st,data1,ss2 = summary_table(model1,alpha = 0.05)
st
fitted_values = data1[:,2]
fitted_values
predict_mean_se = data1[:,3]
predict_mean_se
predict_mean_ci_low,predict_mean_ci_upp = data1[:,4:6].T
predict_ci_low, predict_ci_upp = data1[:,6:8].T
# Lower limit of confidence interval
predict_mean_ci_low
# Upper limit of confidence interval
predict_mean_ci_upp
# Lower limit of prediction interval
predict_ci_low
# Upper limit of prediction interval
predict_ci_upp
fig,ax = plt.subplots(figsize = (8,6))
ax.plot(x,y,'o',label = 'Data')
ax.plot(X,fitted_values,'r-',label = 'OLS')
ax.plot(X,predict_ci_low,'b--')
ax.plot(X,predict_ci_upp,'b--')
ax.plot(X,predict_mean_ci_low,'g--')
ax.plot(X,predict_mean_ci_upp,'g--')
ax.legend(loc = 'best')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12011624152405553, 'fraction_numerical': 0.01646754924120116, 'mean_word_length': 7.2175066312997345, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '475146', 'license': 'MIT', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1038, 'n_words': 269, 'path': 'Linear Regression Estimation.ipynb', 'repo_name': 'shobs-v/NPTEL---Data-Analytics-With-Python', 'size': '3097'}