ML File Final
ML File Final
print("Hello, World!")
Hello, World!
In [2]:
a = 5
b = 3
sum_result = a + b
difference_result = a - b
product_result = a * b
quotient_result = a / b
print("Sum:", sum_result)
print("Difference:", difference_result)
print("Product:", product_result)
print("Quotient:", quotient_result)
Sum: 8
Difference: 2
Product: 15
Quotient: 1.6666666666666667
In [3]:
In [4]:
localhost:8888/notebooks/Lab1.ipynb 1/3
9/20/23, 11:50 AM Lab1 - Jupyter Notebook Gautam Sharma RA2111042030011
In [5]:
total = 0
for i in range(1, 101):
total += i
print("Sum of numbers from 1 to 100:", total)
1
2
3
4
5
6
7
8
9
10
Sum of numbers from 1 to 100: 5050
In [6]:
result = add(7, 4)
print("Result of addition:", result)
Result of addition: 11
In [7]:
fruits.append("orange")
print("Updated fruits:", fruits)
localhost:8888/notebooks/Lab1.ipynb 2/3
9/20/23, 11:50 AM Lab1 - Jupyter Notebook Gautam Sharma RA2111042030011
In [8]:
In [9]:
localhost:8888/notebooks/Lab1.ipynb 3/3
9/20/23, 11:50 AM Lab2 - Jupyter Notebook Gautam Sharma RA2111042030011
import sklearn
In [13]:
iris = load_iris()
X = iris.data
y = iris.target
In [14]:
Model
In [15]:
clf = DecisionTreeClassifier()
In [16]:
clf.fit(X_train, y_train)
Out[16]:
DecisionTreeClassifier()
In a Jupyter environment, please rerun this cell to show the HTML representation or
trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page
with nbviewer.org.
In [17]:
y_pred = clf.predict(X_test)
localhost:8888/notebooks/Lab2.ipynb 1/2
9/20/23, 11:50 AM Lab2 - Jupyter Notebook Gautam Sharma RA2111042030011
In [18]:
Accuracy: 1.0
In [19]:
In [20]:
In [21]:
dump(clf, 'model.joblib')
loaded_model = load('model.joblib')
In [ ]:
localhost:8888/notebooks/Lab2.ipynb 2/2
9/20/23, 11:51 AM Lab3 - Jupyter Notebook Gautam Sharma RA2111042030011
import pandas as pd
import numpy as np
In [2]:
df = pd.read_csv(r'C:\Users\Gautam Sharma\Desktop\Accelerator.csv')
In [3]:
print(df.head())
Sales
0 262
1 732
2 15
3 958
4 22
localhost:8888/notebooks/Lab3.ipynb 1/3
9/20/23, 11:51 AM Lab3 - Jupyter Notebook Gautam Sharma RA2111042030011
In [4]:
print(df.describe())
In [5]:
print(df.isnull().sum())
Segment 0
Category 0
Sub-Category 0
City 0
Order Date 0
Postal Code 11
Region 0
Ship Status 0
State 0
Profit 0
Quantity 0
Sales 0
dtype: int64
In [6]:
df = df.dropna()
localhost:8888/notebooks/Lab3.ipynb 2/3
9/20/23, 11:51 AM Lab3 - Jupyter Notebook Gautam Sharma RA2111042030011
In [7]:
print(df.isnull().sum())
Segment 0
Category 0
Sub-Category 0
City 0
Order Date 0
Postal Code 0
Region 0
Ship Status 0
State 0
Profit 0
Quantity 0
Sales 0
dtype: int64
localhost:8888/notebooks/Lab3.ipynb 3/3
9/20/23, 11:51 AM Lab4 - Jupyter Notebook Gautam Sharma RA2111042030011
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets, linear_model
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, r2_score
In [2]:
diabetes = datasets.load_diabetes()
X = diabetes.data[:, np.newaxis, 2]
y = diabetes.target
In [3]:
In [4]:
regr = linear_model.LinearRegression()
regr.fit(X_train, y_train)
Out[4]:
LinearRegression()
In a Jupyter environment, please rerun this cell to show the HTML representation or
trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page
with nbviewer.org.
In [5]:
y_pred = regr.predict(X_test)
localhost:8888/notebooks/Lab4.ipynb 1/3
9/20/23, 11:51 AM Lab4 - Jupyter Notebook Gautam Sharma RA2111042030011
In [6]:
print('Coefficients:', regr.coef_)
r2 = r2_score(y_test, y_pred)
print('R-squared:', r2)
Coefficients: [998.57768914]
Mean Squared Error: 4061.8259284949268
R-squared: 0.23335039815872138
In [7]:
localhost:8888/notebooks/Lab4.ipynb 2/3
9/20/23, 11:51 AM Lab4 - Jupyter Notebook Gautam Sharma RA2111042030011
localhost:8888/notebooks/Lab4.ipynb 3/3