#Exp2 Eda On 2 Variable Dataset
#Exp2 Eda On 2 Variable Dataset
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, r2_score
df = sns.load_dataset("iris")
# Predictions
y_pred = model.predict(X_test)
# Model evaluation
mse = mean_squared_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)
# Print results
print(f"\nModel Coefficient: {model.coef_[0]:.2f}")
print(f"Model Intercept: {model.intercept_:.2f}")
print(f"Mean Squared Error: {mse:.2f}")
print(f"R2 Score: {r2:.2f}")
plt.figure(figsize=(8, 6))
sns.scatterplot(x=X_test['sepal_length'], y=y_test, hue=df['species'],palette="viridis",
legend=False)
sns.lineplot(x=X_test['sepal_length'], y=y_pred, color='red',label='Regression Line')
plt.xlabel("Sepal Length")
plt.ylabel("Petal Length")
plt.title("Linear Regression: Sepal Length vs Petal Length")
plt.legend()
plt.show()
# Load dataset
data = sns.load_dataset('iris')
# Use Sepal & Petal features (X) and Petal Length as target (y)
X = data[['sepal_length', 'sepal_width', 'petal_length', 'petal_width']].values
y = data['petal_length'].values
species = data['species']
plt.tight_layout()
plt.show()
#EXP 4
Classification of a dataset from UCI repository using a perceptron with bias
and without bias
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import Perceptron
from sklearn.metrics import accuracy_score
from sklearn.datasets import make_classification