File size: 2,176 Bytes
5ff5b0c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# -*- coding: utf-8 -*-
"""Tracingonlinedating.159
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1OkkJMge8YJRdezVwRU92t1timr9gJw9M
"""
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
df = pd.read_csv("/content/Online_Dating_Behavior_Dataset.csv")
print(df.head())
print(df.describe())
print(df.isnull().sum())
plt.figure(figsize=(10, 6))
sns.histplot(df['Matches'], bins=30, kde=True)
plt.title('Distribution of Matches')
plt.xlabel('Number of Matches')
plt.ylabel('Frequency')
plt.show()
sns.pairplot(df)
plt.show()
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
numerical_features = ['Income', 'Age', 'Attractiveness', 'Children']
df[numerical_features] = scaler.fit_transform(df[numerical_features])
X = df.drop('Matches', axis=1)
y = df['Matches']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
print("Training set shape:", X_train.shape)
print("Testing set shape:", X_test.shape)
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error, r2_score
lr_model = LinearRegression()
rf_model = RandomForestRegressor(random_state=42)
lr_model.fit(X_train, y_train)
y_pred_lr = lr_model.predict(X_test)
print("Linear Regression - RMSE:", mean_squared_error(y_test, y_pred_lr, squared=False))
print("Linear Regression - R^2 Score:", r2_score(y_test, y_pred_lr))
rf_model.fit(X_train, y_train)
y_pred_rf = rf_model.predict(X_test)
print("Random Forest - RMSE:", mean_squared_error(y_test, y_pred_rf, squared=False))
print("Random Forest - R^2 Score:", r2_score(y_test, y_pred_rf))
importance = rf_model.feature_importances_
features = X.columns
indices = np.argsort(importance)[::-1]
plt.figure(figsize=(12, 6))
plt.title("Feature Importances")
plt.bar(range(X.shape[1]), importance[indices], align="center")
plt.xticks(range(X.shape[1]), features[indices], rotation=90)
plt.xlim([-1, X.shape[1]])
plt.show()
|