From 7a6f573d265e05c0e0679f06a50b41b4b5f4916c Mon Sep 17 00:00:00 2001 From: Yevhenii Poliakov Date: Sun, 14 May 2023 22:31:23 +0200 Subject: [PATCH] upd52 --- script5_2.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 script5_2.py diff --git a/script5_2.py b/script5_2.py new file mode 100644 index 0000000..18b770c --- /dev/null +++ b/script5_2.py @@ -0,0 +1,41 @@ +import pandas as pd +from sklearn.model_selection import train_test_split +from sklearn.preprocessing import LabelEncoder +from keras.models import Sequential +from keras.layers import Dense + +# Load the dataset +df = pd.read_csv('movie_dataset.csv') + +# Select the relevant columns (e.g., 'Rating' and 'Writer') +data = df[['Rating', 'Writer']] + +# Drop rows with missing values +data = data.dropna() + +# Convert the 'Writer' column to numeric using label encoding +encoder = LabelEncoder() +data['Writer'] = encoder.fit_transform(data['Writer']) + +# Split the data into training and testing sets +X = data['Writer'] +y = data['Rating'] + +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) + +# Create the neural network model +model = Sequential() +model.add(Dense(64, activation='relu', input_dim=1)) +model.add(Dense(1)) + +model.compile(loss='mean_squared_error', optimizer='adam') + +# Train the model +model.fit(X_train, y_train, batch_size=64, epochs=10, validation_data=(X_test, y_test)) + +# Make predictions on new data +new_writer = 'John Smith' +new_writer_encoded = encoder.transform([new_writer]) + +rating_prediction = model.predict(new_writer_encoded) +print("Predicted rating for the writer 'John Smith':", rating_prediction) \ No newline at end of file