upd52
This commit is contained in:
parent
1ca016f489
commit
7a6f573d26
41
script5_2.py
Normal file
41
script5_2.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user