update script4

This commit is contained in:
Yevhenii Poliakov 2023-05-14 17:58:00 +02:00
parent c3282144cd
commit bd09cb0dd1

View File

@ -5,8 +5,7 @@ from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler from sklearn.preprocessing import StandardScaler
# Step 1: Load the dataset # Step 1: Load the dataset
data = pd.read_csv('25k_movies.csv.shuf') data = pd.read_csv('25k_movies.csv.shuf', error_bad_lines=False)
# Replace 'path_to_dataset.csv' with the actual path to your dataset file
# Step 2: Preprocess the data # Step 2: Preprocess the data
features = ['Total Run Time', 'User Rating', 'Genres', 'Director Name', 'Writer Name'] features = ['Total Run Time', 'User Rating', 'Genres', 'Director Name', 'Writer Name']
@ -16,6 +15,9 @@ data = data[features + [target]]
# Handle missing values if any # Handle missing values if any
data = data.dropna() data = data.dropna()
# Filter out rows with a different number of columns
data = data[data.apply(lambda x: len(x) == 12, axis=1)]
# Convert categorical variables to numerical representations # Convert categorical variables to numerical representations
data = pd.get_dummies(data, columns=['Genres', 'Director Name', 'Writer Name']) data = pd.get_dummies(data, columns=['Genres', 'Director Name', 'Writer Name'])
@ -46,4 +48,4 @@ model.fit(X_train, y_train, epochs=10, batch_size=32)
y_pred = model.predict(X_test) y_pred = model.predict(X_test)
mse = np.mean((y_pred - y_test)**2) mse = np.mean((y_pred - y_test)**2)
print(f"Mean Squared Error (MSE): {mse}") print(f"Mean Squared Error (MSE): {mse}")