<jupyter_start><jupyter_text>Data Exploration and Visulization<jupyter_code>df
df.shape
df.isnull().sum()
df.duplicated()
df.info()
df.describe()
df.max()
df.min()
Max_Marks_Details = df[df['Marks'] == 55.299]
Max_Marks_Details
Min_Marks_Details = df[df['Marks'] == 5.609]
Min_Marks_Details
df['Marks'].hist()
df['time_study'].hist()
df['number_courses'].hist()<jupyter_output><empty_output><jupyter_text>Methodology<jupyter_code>plt.scatter(x = df.time_study, y = df.Marks)
plt.xlabel("Student study time")
plt.ylabel("Student marks")
plt.title("Scatter Plot of Student Study Time vs Student Marks")
plt.show()
df
df__ = df.copy()
df__<jupyter_output><empty_output><jupyter_text>Below i will drop number of courses as I will not use it in my prediction because the goal of prediction is to predict the student marks depent of the averate study timee<jupyter_code>new_df = df__.drop('number_courses' , axis=1)
new_df<jupyter_output><empty_output><jupyter_text>Data Splitting to split data into a train and test<jupyter_code>X = new_df.drop("Marks", axis = "columns")
y = new_df.drop("time_study", axis = "columns")
print ("Shape of X = ", X.shape)
print ("Shape of y = ", y.shape)
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.2, random_state=51 )
print ("The shape of X_train = ", X_train.shape)
print ("The shape of y_train = ", y_train.shape)
print ("The shape of X_test = ", X_test.shape)
print ("The shape of y_test = ", y_test.shape)<jupyter_output>The shape of X_train =  (80, 1)
The shape of y_train =  (80, 1)
The shape of X_test =  (20, 1)
The shape of y_test =  (20, 1)<jupyter_text>Applying the Linear Regression<jupyter_code>linearrr = LinearRegression()
linearrr.fit(X_train , y_train)
y_predition = linearrr.predict(X_test)
y_predition
df_actual_and_predicted_ = pd.DataFrame( np.c_[X_test,y_test,y_predition], columns = ["time_study","the original marks","Predicted marks"] )
df_actual_and_predicted_
#Plotting the bar graph to see the difference between the actual and predicted marks

df_actual_and_predicted_.plot(kind='bar', figsize=(5,5))
plt.grid(which='major' , linewidth='0.5' , color='red')
plt.grid(which='minor' , linewidth='0.5' , color='blue')
plt.show()<jupyter_output><empty_output><jupyter_text>The accuracy of the model<jupyter_code>linearrr.score(X_test,y_test)
plt.scatter(X_train,y_train)
plt.scatter(X_test,y_test)
plt.plot(X_train, linearrr.predict(X_train), color = "b" )<jupyter_output><empty_output><jupyter_text>Model Evaluation<jupyter_code>time_study = 9
test = np.array([time_study])
test = test.reshape(-1,1)
own_pred = linearrr.predict(test)
print("Number of average time per day to study = {}".format(time_study))
print("Predicted Score = {}".format(own_pred[0]))
from sklearn import metrics  
print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_predition)) 
print('Mean Squared Error:', metrics.mean_squared_error(y_test,y_predition))
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test,y_predition)))
#R2 score is a metric that tells the performance of your model, not the loss in an absolute sense that how many wells did your model perform.
r2 = r2_score(y_test,y_predition)
print('R2:' , r2)<jupyter_output>R2: 0.8826200571575015<jupyter_text>Grid Search<jupyter_code>linearrr.get_params().keys()
paramss = {
 'copy_X': [True], 
 'fit_intercept': [False], 
 'normalize': [True],     
}
grid_linear= GridSearchCV(estimator=linearrr, param_grid = paramss, cv = 2, n_jobs=-1)
grid_linear.fit(X_train, y_train)
dfff = grid_linear.cv_results_
dfff
dfff_ = pd.DataFrame(grid_linear.cv_results_)
dfff_
print(" Results from Grid Search:" )
print("\n The best estimator across ALL searched params:\n",grid_linear.best_estimator_)
print("\n The best score across ALL searched params:\n",grid_linear.best_score_)
print("\n The best parameters across ALL searched params:\n",grid_linear.best_params_)<jupyter_output>Results from Grid Search 

 The best estimator across ALL searched params:
 LinearRegression(copy_X=True, fit_intercept=False, n_jobs=None, normalize=True)

 The best score across ALL searched params:
 0.8776259233291857

 The best parameters across ALL searched params:
 {'copy_X': True, 'fit_intercept': False, 'normalize': True}
{'fraction_non_alphanumeric': 0.1282051282051282, 'fraction_numerical': 0.01834862385321101, 'mean_word_length': 7.03780718336484, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '55121', 'license': 'FTL', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1510, 'n_words': 368, 'path': 'Studentttt Marks Prediction for Data Science Capstone1.ipynb', 'repo_name': 'Lama292929/Student-Marks-Prediction--for-Data-Science-Capstone-', 'size': '4251'}