<jupyter_start><jupyter_text>Importing Pandas<jupyter_code>import pandas as pd<jupyter_output><empty_output><jupyter_text>df = pd.read_csv('rename.ext')  csv file df = pd.read_excel('home.xlsx')df.head()  Get the Working Directory<jupyter_code>import os
os.getcwd()<jupyter_output><empty_output><jupyter_text>Change Working Directory<jupyter_code>os.chdir('C:\\Users\\study mart\\Desktop\\New folder')
os.getcwd()<jupyter_output><empty_output><jupyter_text>Read CSV File<jupyter_code>df = pd.read_csv('home2.csv')
df.head()
import matplotlib.pyplot as plt
import numpy as np
df.tail()<jupyter_output><empty_output><jupyter_text>Null Checking<jupyter_code>#df.isnull().values.any()
df.isnull().sum()
df['area'].head()<jupyter_output><empty_output><jupyter_text>Showing & Saving Scatter Plot<jupyter_code>plt.title('Homeprices in Dhanmodi')
plt.xlabel('Area in sq')
plt.ylabel('Price / Rent')
plt.scatter(df['area'],df['rent'],color='red',marker='*') #https://matplotlib.org/stable/api/markers_api.html
#plt.savefig('rename.png')

# Sep dept & Ind Variables
# y = mx + c
x = df[['area']]
y = df['rent']
x.head()<jupyter_output><empty_output><jupyter_text>total data = 100%train = 70%test = 30%  Dividing Training & Testing Data<jupyter_code># split train and test data
from sklearn.model_selection import train_test_split
xtrain, xtest, ytrain, ytest = train_test_split(x,y,train_size=.70)
xtrain.head()
ytrain.head()
df.head()
xtest.shape
xtrain.shape<jupyter_output><empty_output><jupyter_text>Linear Regression<jupyter_code>#Linear Regression
from sklearn.linear_model import LinearRegression
reg = LinearRegression()
reg.fit(xtrain,ytrain) #training your ml model<jupyter_output><empty_output><jupyter_text>Predicting value<jupyter_code>reg.predict([[2200]])
m = reg.coef_
c = reg.intercept_
x = 2200
y = m*x + c
y
reg.coef_
reg.intercept_
ytest
prediction = reg.predict(xtest)
prediction<jupyter_output><empty_output><jupyter_text>Error Detecting<jupyter_code>from sklearn.metrics import mean_squared_error
mse = mean_squared_error(ytest,prediction)
mse<jupyter_output><empty_output><jupyter_text>Best Fit Line<jupyter_code>plt.plot(df.area, reg.predict(df[['area']]))
plt.title('Homeprices in Dhanmodi')
plt.xlabel('Area in sq')
plt.ylabel('Price / Rent')
plt.scatter(df['area'],df['rent'],color='red',marker='*') #https://matplotlib.org/stable/api/markers_api.html
#plt.savefig('rename.png')
reg.score(xtest,ytest)<jupyter_output><empty_output><jupyter_text>Save Trained Model<jupyter_code>import pickle as pk
pk.dump(reg,open('My_Linear_Model_pk','wb')) #write mode<jupyter_output><empty_output><jupyter_text>Joblib<jupyter_code>import joblib as jbl
jbl.dump(reg,'My2')
model2 = jbl.load('My2')
model2.predict([[2200]])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15245009074410162, 'fraction_numerical': 0.009437386569872959, 'mean_word_length': 9.322097378277153, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 2, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '280411', 'license': 'MIT', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1084, 'n_words': 156, 'path': 'class-4/Class 04 - Linear Regression.ipynb', 'repo_name': 'Anikcb/Machine_Learning_Daffodil', 'size': '2755'}