Vicky Patil - Practical - 9 - Colab
Vicky Patil - Practical - 9 - Colab
Practical No.9
Name:-Vicky v patil
Title of Practical:-Read a data which will give a proper distribution curve using pandas. Apply preprocessing on the data and plot a histogram
for the same. Properly label the plot. Analyze the plot
import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import LabelEncoder
from sklearn.impute import SimpleImputer
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.linear_model import LinearRegression
#
df=pd.read_csv('/content/Iris.csv')
df
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).
print(df.isnull().sum())
Id 0
SepalLengthCm 0
SepalWidthCm 0
PetalLengthCm 0
PetalWidthCm 0
Species 0
dtype: int64
le=LabelEncoder()
df['Species']=le.fit_transform(df['Species'])
df
https://colab.research.google.com/drive/1S8CI8u92AuPe6vwKOCNQdusyjrCoArqs?usp=sharing#scrollTo=HsAEcmTrKUV0&printMode=true 1/4
12/3/24, 4:15 PM Vicky patil_Practical_9 - Colab
x=df[df.columns[0:3]]
y=df[df.columns[4]]
df.shape
(150, 6)
x.head()
Id SepalLengthCm SepalWidthCm
0 1 5.1 3.5
1 2 4.9 3.0
2 3 4.7 3.2
3 4 4.6 3.1
4 5 5.0 3.6
y.head()
PetalWidthCm
0 0.2
1 0.2
2 0.2
3 0.2
4 0.2
dtype: float64
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,random_state=10)
x_train.head()
Id SepalLengthCm SepalWidthCm
32 33 5.2 4.1
52 53 6.9 3.1
70 71 5.9 3.2
y_train.head()
https://colab.research.google.com/drive/1S8CI8u92AuPe6vwKOCNQdusyjrCoArqs?usp=sharing#scrollTo=HsAEcmTrKUV0&printMode=true 2/4
12/3/24, 4:15 PM Vicky patil_Practical_9 - Colab
PetalWidthCm
32 0.1
52 1.5
70 1.8
121 2.0
144 2.5
dtype: float64
R-squared: 0.8627149401415144
md=LinearRegression()
md.fit(x_train,y_train)
▾ LinearRegression i ?
LinearRegression()
y_pred=md.predict(x_test)
y_pred
r2 = r2_score(y_test, y_pred)
print(f"R-squared: {r2}")
R-squared: 0.8627149401415144
Mean Squared Error: 0.07482273045106973
plt.figure(figsize=(9,6))
sns.histplot(df['Species'])
plt.title('Distribution of Species')
plt.xlabel('Species')
plt.ylabel('Count')
plt.show()
https://colab.research.google.com/drive/1S8CI8u92AuPe6vwKOCNQdusyjrCoArqs?usp=sharing#scrollTo=HsAEcmTrKUV0&printMode=true 3/4
12/3/24, 4:15 PM Vicky patil_Practical_9 - Colab
https://colab.research.google.com/drive/1S8CI8u92AuPe6vwKOCNQdusyjrCoArqs?usp=sharing#scrollTo=HsAEcmTrKUV0&printMode=true 4/4