<jupyter_start><jupyter_text>Importing Data<jupyter_code>data=pd.read_csv('Position_Salaries.csv')
print(data.head())
data.info()
data.describe()<jupyter_output><empty_output><jupyter_text>Checking for null entries<jupyter_code>data.isnull().sum()<jupyter_output><empty_output><jupyter_text>Data Splitting<jupyter_code>x=data.iloc[:,1].values.reshape(-1,1)
y=data.iloc[:,-1].values.reshape(-1,1)
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=1)<jupyter_output><empty_output><jupyter_text>Linear Regression Model<jupyter_code>from sklearn.linear_model import LinearRegression
lr=LinearRegression()
lr.fit(x_train,y_train)
lr_pre=lr.predict(x_test)
print(lr_pre)
lr.score(x_train,y_train)
from sklearn.metrics import r2_score
r2_score(y_test,lr_pre)
plt.scatter(x,y,color='red')
plt.plot(x_train,lr.predict(x_train),color='blue')
plt.xlabel('Grade')
plt.ylabel('Salary')
plt.show()<jupyter_output><empty_output><jupyter_text>Polynomial Linear regression Model<jupyter_code>from sklearn.preprocessing import PolynomialFeatures
pf=PolynomialFeatures(degree=2)
x_p=pf.fit_transform(x)
lr_2=LinearRegression()
lr_2.fit(x_p,y)
plt.scatter(x,y,color='red')
plt.plot(x,lr_2.predict(x_p),color='blue')
lr_2.score(x_p,y)<jupyter_output><empty_output><jupyter_text>Result of changing degree<jupyter_code>from sklearn.preprocessing import PolynomialFeatures
pf=PolynomialFeatures(degree=4)
x_p=pf.fit_transform(x)
lr_3=LinearRegression()
lr_3.fit(x_p,y)
plt.scatter(x,y,color='red')
plt.plot(x,lr_3.predict(x_p),color='blue')
lr_3.score(x_p,y)
r2_score(y,lr_3.predict(x_p))<jupyter_output><empty_output><jupyter_text>Predicting using final model<jupyter_code>lr_3.predict(pf.fit_transform([[6.6]]))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14944444444444444, 'fraction_numerical': 0.014444444444444444, 'mean_word_length': 15.080357142857142, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '69443', 'license': 'Apache-2.0', 'n_tokens_mistral': 770, 'n_tokens_neox': 753, 'n_words': 65, 'path': 'Polinimial_Linear_Regression.ipynb', 'repo_name': 'Legolas1086/Polynomial_Linear_Regression', 'size': '1800'}