image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
from sklearn.ensemble import RandomForestRegressor
from sklearn.feature_selection import SelectFromModel
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score
from sklearn.metrics import mean_squared_error
import lightgbm as lgb
from catboost import CatBoostRegressor
from sklearn.linear_model import Ridge
from sklearn.linear_model import ElasticNet
sns.set_style('darkgrid')
pd.options.display.float_format = '{:.4f}'.format

df = pd.read_csv('/kaggle/input/wikihow-features/wikihow.csv')

df[['references_count', 'references_count_per_text_length', 'references_count_per_method']] = df[['references_count', 'references_count_per_text_length', 'references_count_per_method']].fillna(0)
df = df.dropna(subset=['views', 'co_authors'])

df.describe().T

plt.axis('equal')

expert_articles = df[df['is_expert'] == 1]
non_expert_articles = df[df['is_expert'] == 0]

# Create a grid of plots with 1 row and 3 columns
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(20,7))

# Plot the histogram of percent helpful for non-expert and expert articles
axes[0].hist(non_expert_articles['percent_helpful'], bins=50, alpha=0.4, label='Non-Expert', density=True)
axes[0].hist(expert_articles['percent_helpful'], bins=50, alpha=0.5, label='Expert', density=True)
axes[0].set_xlabel('Percent Helpful')
axes[0].set_xlim(70,100)
axes[0].legend(loc='upper left')

# Plot the strip plot of percent helpful by expert
sns.stripplot(x='is_expert', y='percent_helpful', data=df, jitter=0.35, ax=axes[1]) # type: ignore

# Plot the bar plot of percent helpful by expert
sns.barplot(x='is_expert', y='percent_helpful', data=df, errorbar=None, width=0.5, ax=axes[2])
axes[2].set_xlabel('Is Expert')
axes[2].set_ylabel('Percent Helpful')
axes[2].axhline(y=88.3, color='green', linestyle='--')
axes[2].set_ylim(50,90)

# Adjust the layout
plt.tight_layout()

# Show the plot
plt.show()

# Create a grid of plots with 1 row and 2 columns
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(20,7))

# Plot the histogram of character count for non-expert articles

axes[0].hist(non_expert_articles['character_count'], bins=50, alpha=0.4, label='Non-Expert', density=True)
axes[0].hist(expert_articles['character_count'], bins=50, alpha=0.5, label='Expert', density=True)
axes[0].set_xlabel('Number of Characters')
axes[0].set_ylabel('Count')
axes[0].set_xlim(0,18000)
axes[0].set_yticks([])

# Plot the histogram of character count for expert articles
axes[1].hist(non_expert_articles['word_count'], bins=50, alpha=0.4, label='Non-Expert', density=True)
axes[1].hist(expert_articles['word_count'], bins=50, alpha=0.5, label='Expert', density=True)
axes[1].set_xlabel('Number of Words')
axes[1].set_xlim(0,4000)
axes[1].set_yticks([])

sns.regplot(x='character_count', y='word_count', data=df, line_kws={'color': 'red'}, ax=axes[2])

# Add legend
axes[0].legend(loc='upper right')
axes[1].legend(loc='upper right')

# Display the plots
plt.tight_layout()
plt.show()

fig, ax = plt.subplots(figsize=(10, 6))
sns.kdeplot(non_expert_articles['mean_paragraph_size'], fill=True, alpha=0.4, label='Non-Expert', ax=ax)
sns.kdeplot(expert_articles['mean_paragraph_size'], fill=True, alpha=0.4, label='Expert', ax=ax)
ax.set_xlabel('Mean Paragraph Size')
ax.set_ylabel('Density')
ax.set_title('Distribution of Mean Paragraph Size in Expert and Non-Expert Articles')
ax.legend(loc='upper right')
plt.xlim(0, 1000)
plt.show()