text_plain_output_1.png
from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.linear_model import LinearRegression

from sklearn.linear_model import Ridge

from sklearn.model_selection import train_test_split

from sklearn.pipeline import make_pipeline

from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import xgboost as xgb

train_df = pd.read_csv('/kaggle/input/commonlitreadabilityprize/train.csv')
train_df.drop(train_df[(train_df.target == 0) & (train_df.standard_error == 0)].index, inplace=True)
train_df.reset_index(drop=True, inplace=True)
test_df = pd.read_csv('/kaggle/input/commonlitreadabilityprize/test.csv')
submission_df = pd.read_csv('/kaggle/input/commonlitreadabilityprize/sample_submission.csv')

target_mean = train_df['target'].mean()
target_median = train_df['target'].median()
target_std = train_df['target'].std()
target_min = train_df['target'].min()
target_25 = np.percentile(train_df['target'], 25)
target_50 = np.percentile(train_df['target'], 50)
target_75 = np.percentile(train_df['target'], 75)
target_max = train_df['target'].max()
target_skew = train_df['target'].skew(axis=0, skipna=True)

standard_error_mean = train_df['standard_error'].mean()
standard_error_median = train_df['standard_error'].median()
standard_error_std = train_df['standard_error'].std()
standard_error_min = train_df['standard_error'].min()
standard_error_25 = np.percentile(train_df['standard_error'], 25)
standard_error_50 = np.percentile(train_df['standard_error'], 50)
standard_error_75 = np.percentile(train_df['standard_error'], 75)
standard_error_max = train_df['standard_error'].max()
standard_error_skew = train_df['target'].skew(axis=0, skipna=True)

text = train_df.excerpt[0]
wordcloud = WordCloud().generate(text)
wordcloud = WordCloud(max_font_size=50, max_words=100, background_color='white').generate(text)
wordcloud.generate(' '.join(train_df['excerpt_preprocessed']))
plt.axis('off')

def training(model, X_train, y_train, X_test, y_test):
    model = make_pipeline(TfidfVectorizer(binary=True, ngram_range=(1, 1)), model)
    model.fit(X_train, y_train)
    y_pred = model.predict(X_test)
    MSE = mse(y_test, y_pred)
xg = xgb.XGBRegressor(objective='reg:squarederror', colsample_bytree=0.3, learning_rate=0.1, max_depth=5, alpha=10, n_estimators=10)
ridge = Ridge(fit_intercept=True, normalize=False)
lr = LinearRegression()
m = [xg, ridge, lr]
mn = ['XGBoost Regression', 'Ridge Regression', 'Linear Regression']
print('Model:', mn)
print('Mean Squared Error:', MSE)
X = train_df['excerpt_preprocessed'].values
y = train_df['target'].values
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
for i in range(0, len(m)):
    training(model=m[i], X_train=X_train, y_train=y_train, X_test=X_test, y_test=y_test)