upd51
This commit is contained in:
parent
c3c751076e
commit
2d8d1d999e
19
script5_1.py
19
script5_1.py
@ -7,27 +7,28 @@ from tensorflow.keras.layers import Dense
|
||||
from tensorflow.keras.optimizers import Adam
|
||||
|
||||
# Load the dataset from the CSV file
|
||||
data = pd.read_csv('data.csv', on_bad_lines='skip', engine='python')
|
||||
|
||||
data = pd.read_csv('data.csv')
|
||||
|
||||
# Drop a specific row
|
||||
data = data.drop(index=5059)
|
||||
|
||||
# Prepare the data
|
||||
X = data[['movie title', 'User Rating', 'Director', 'Top 5 Casts', 'Writer', 'year']]
|
||||
X = data[['movie title', 'User Rating', 'Director', 'Top 5 Casts', 'Writer']]
|
||||
y = data['Rating']
|
||||
|
||||
# Preprocess the data
|
||||
# Convert the categorical columns into numerical representations
|
||||
mlb_genres = MultiLabelBinarizer()
|
||||
X_genres = mlb_genres.fit_transform(data['Generes'])
|
||||
X.loc[:, 'Generes'] = X_genres.tolist()
|
||||
X_genres = pd.DataFrame(mlb_genres.fit_transform(data['Generes']), columns=mlb_genres.classes_)
|
||||
|
||||
mlb_keywords = MultiLabelBinarizer()
|
||||
X_keywords = mlb_keywords.fit_transform(data['Plot Kyeword'])
|
||||
X.loc[:, 'Plot Kyeword'] = X_keywords.tolist()
|
||||
X_keywords = pd.DataFrame(mlb_keywords.fit_transform(data['Plot Kyeword']), columns=mlb_keywords.classes_)
|
||||
|
||||
mlb_casts = MultiLabelBinarizer()
|
||||
X_casts = mlb_casts.fit_transform(data['Top 5 Casts'].astype(str))
|
||||
X.loc[:, 'Top 5 Casts'] = X_casts.tolist()
|
||||
X_casts = pd.DataFrame(mlb_casts.fit_transform(data['Top 5 Casts'].astype(str)), columns=mlb_casts.classes_)
|
||||
|
||||
# Concatenate the transformed columns with the remaining columns
|
||||
X = pd.concat([X, X_genres, X_keywords, X_casts], axis=1)
|
||||
|
||||
# Split the data into training and testing sets
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
||||
|
Loading…
Reference in New Issue
Block a user