Practical 3
Practical 3
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.feature_selection import SelectKBest, f_regression
# Remove non-numeric columns like 'car name' (or any other categorical columns)
df = df.drop(columns=['car name']) # Dropping the 'car name' column
# If there are any other categorical columns, encode them (e.g., using one-hot
encoding)
# df = pd.get_dummies(df, drop_first=True) # Uncomment if you have categorical
features
plt.figure(figsize=(10, 6))
sns.barplot(x='Feature', y='Score', data=feature_scores)
plt.title('Feature Selection Scores')
plt.xticks(rotation=45)
plt.show()
# Selecting top 3 features (example)
top_features = feature_scores.nlargest(3, 'Score')['Feature'].tolist()
print("\nTop 3 Relevant Features:")
print(top_features)