Update app.py
Browse files
app.py
CHANGED
|
@@ -128,17 +128,34 @@ combined_niche_trends = combined_df.groupby('content_type')['sentiment'].mean().
|
|
| 128 |
logging.info("Top Performing Content Types by Sentiment (Combined Data):")
|
| 129 |
print(combined_niche_trends)
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
# Enhanced viral potential prediction using combined data
|
| 132 |
logging.info("Training enhanced viral potential prediction model using combined data...")
|
| 133 |
combined_viral_threshold = combined_df['engagement_rate'].quantile(0.9)
|
| 134 |
combined_df['viral'] = combined_df['engagement_rate'].apply(lambda x: 1 if x >= combined_viral_threshold else 0)
|
| 135 |
|
| 136 |
-
#
|
| 137 |
-
features = ['caption_length', 'hashtag_count', 'sentiment', 'content_type_encoded', 'media_type_encoded']
|
| 138 |
X = combined_df[features]
|
| 139 |
y = combined_df['viral']
|
| 140 |
|
| 141 |
-
# Split data into training and testing sets
|
| 142 |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 143 |
|
| 144 |
# Train a Random Forest Classifier
|
|
|
|
| 128 |
logging.info("Top Performing Content Types by Sentiment (Combined Data):")
|
| 129 |
print(combined_niche_trends)
|
| 130 |
|
| 131 |
+
# Encode categorical columns if they exist
|
| 132 |
+
if 'content_type' in combined_df.columns and 'media_type' in combined_df.columns:
|
| 133 |
+
logging.info("Encoding categorical columns...")
|
| 134 |
+
label_encoder = LabelEncoder()
|
| 135 |
+
combined_df['content_type_encoded'] = label_encoder.fit_transform(combined_df['content_type'])
|
| 136 |
+
combined_df['media_type_encoded'] = label_encoder.fit_transform(combined_df['media_type'])
|
| 137 |
+
else:
|
| 138 |
+
logging.warning("'content_type' or 'media_type' columns not found. Skipping encoding.")
|
| 139 |
+
|
| 140 |
+
# Update the features list
|
| 141 |
+
if 'content_type_encoded' in combined_df.columns and 'media_type_encoded' in combined_df.columns:
|
| 142 |
+
features = ['caption_length', 'hashtag_count', 'sentiment', 'content_type_encoded', 'media_type_encoded']
|
| 143 |
+
else:
|
| 144 |
+
logging.warning("Using reduced feature set because encoded columns are missing.")
|
| 145 |
+
features = ['caption_length', 'hashtag_count', 'sentiment']
|
| 146 |
+
|
| 147 |
+
# Log the features being used
|
| 148 |
+
logging.info(f"Features for model training: {features}")
|
| 149 |
+
|
| 150 |
# Enhanced viral potential prediction using combined data
|
| 151 |
logging.info("Training enhanced viral potential prediction model using combined data...")
|
| 152 |
combined_viral_threshold = combined_df['engagement_rate'].quantile(0.9)
|
| 153 |
combined_df['viral'] = combined_df['engagement_rate'].apply(lambda x: 1 if x >= combined_viral_threshold else 0)
|
| 154 |
|
| 155 |
+
# Split data into training and testing sets
|
|
|
|
| 156 |
X = combined_df[features]
|
| 157 |
y = combined_df['viral']
|
| 158 |
|
|
|
|
| 159 |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 160 |
|
| 161 |
# Train a Random Forest Classifier
|