Experiment 6-7-8
Experiment 6-7-8
# Train Random Forest models with varying tree counts and record accuracy
for n_trees in tree_counts:
model = RandomForestClassifier(n_estimators=n_trees, random_state=42)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
accuracies.append(accuracy)
Output :
Experiment 7 : Linear Regression
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.linear_model import LinearRegression
dataset = pd.read_csv('Salary.csv')
x = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 1].values
# x = x.reshape(-1,1)
liner = LinearRegression()
liner.fit(x,y)
y_pred = liner.predict(x)
plt.scatter(x,y)
plt.plot(x,y_pred,color='red')
plt.show()
Output:
Experiment 8 : Logistic Regression
# Make predictions
y_pred = log_reg.predict(X_test)
df_cm = pd.DataFrame(cm)
plt.figure(figsize=(5, 3))
sns.heatmap(df_cm, annot=True, annot_kws={"size": 30}, fmt='d', cmap='Blues')
plt.title('Confusion Matrix')
plt.show()
Output: