update script4.py
This commit is contained in:
parent
bd09cb0dd1
commit
75381edb56
@ -5,7 +5,8 @@ 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', error_bad_lines=False)
|
data = pd.read_csv('25k_movies.csv.shuf')
|
||||||
|
|
||||||
|
|
||||||
# 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,7 +17,12 @@ data = data[features + [target]]
|
|||||||
data = data.dropna()
|
data = data.dropna()
|
||||||
|
|
||||||
# Filter out rows with a different number of columns
|
# Filter out rows with a different number of columns
|
||||||
|
try:
|
||||||
data = data[data.apply(lambda x: len(x) == 12, axis=1)]
|
data = data[data.apply(lambda x: len(x) == 12, axis=1)]
|
||||||
|
except pd.errors.ParserError as e:
|
||||||
|
print(f"Error occurred while parsing the dataset: {e}")
|
||||||
|
print("Dropping rows with inconsistent number of columns...")
|
||||||
|
data = data[data.apply(lambda x: len(x) == 12 if isinstance(x, list) else True, 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'])
|
||||||
|
Loading…
Reference in New Issue
Block a user