<jupyter_start><jupyter_text>Preprocessing  Treating the Null Values<jupyter_code># To find the Null Values
df.isna().sum()
df.fillna(method="bfill",inplace=True)
df.isna().sum()<jupyter_output><empty_output><jupyter_text>Treat the categorical Variable<jupyter_code>from sklearn.preprocessing import LabelEncoder
le=LabelEncoder()
df["Species"]=le.fit_transform(df["Species"])
df.head()<jupyter_output><empty_output><jupyter_text>Feature Scaling<jupyter_code>from sklearn.preprocessing import MinMaxScaler
mm=MinMaxScaler()
x=df.iloc[:,0:4]
scaled=mm.fit_transform(x)
scaled
df.columns
df_new=pd.DataFrame(scaled,columns=['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm','PetalWidthCm'])
df_new.head()
df_new["Species"]=df.Species
df_new.head()<jupyter_output><empty_output><jupyter_text>Splitting of Train and Test<jupyter_code>from sklearn.model_selection import train_test_split
x=df_new.iloc[:,1:5]
y=df_new.SepalLengthCm
xtrain,xtest,ytrain,ytest=train_test_split(x,y,train_size=0.8,random_state=1,shuffle=True)
print(xtrain.shape)
print(ytrain.shape)
print(xtest.shape)
print(ytest.shape)<jupyter_output>(120, 4)
(120,)
(30, 4)
(30,)<jupyter_text>Learning<jupyter_code>from sklearn.linear_model import LinearRegression
lr=LinearRegression()
lr.fit(xtrain,ytrain)<jupyter_output><empty_output><jupyter_text>Evaluation<jupyter_code>ypred=lr.predict(xtest)
ypred
from sklearn.metrics import r2_score, mean_absolute_error
print(r2_score(ytest,ypred))
print(mean_absolute_error(ytest,ypred))<jupyter_output>0.7608853181449958
0.08942021167342325<jupyter_text>Prediction<jupyter_code># Unseen Example
xnew=np.array([0.26,0.03,0.06,0]).reshape(1, -1)
mypred=lr.predict(xnew)
mypred<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13859649122807016, 'fraction_numerical': 0.03976608187134503, 'mean_word_length': 14.008771929824562, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '282802', 'license': 'Apache-2.0', 'n_tokens_mistral': 742, 'n_tokens_neox': 697, 'n_words': 76, 'path': 'First ML - Regression.ipynb', 'repo_name': 'ShravyaRNadig/ML-Unit1', 'size': '1710'}