antitheft159 commited on
Commit
5ff5b0c
1 Parent(s): 3447c89

Upload tracingonlinedating_159.py

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