text_plain_output_1.png
from sklearn.feature_selection import chi2

from sklearn.preprocessing import LabelEncoder

from sklearn.preprocessing import MinMaxScaler

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

train_data = pd.read_csv('/kaggle/input/playground-series-s3e13/train.csv')
test_data = pd.read_csv('/kaggle/input/playground-series-s3e13/test.csv')

plt.xticks(rotation=90)

train_data['symptom_sum'] = train_data.iloc[:, 1:-1].sum(axis=1)

X = train_data.drop(['id', 'prognosis'], axis=1).reset_index(drop=True)
y = train_data['prognosis'].reset_index(drop=True)
le = LabelEncoder()
y = le.fit_transform(y)
y = np.array(y)
scaler = MinMaxScaler()
X_scaled = scaler.fit_transform(X)

scores, p_values = chi2(X_scaled, y)
feature_scores = {feature: score for feature, score in zip(X.columns, p_values)}
sorted_scores = sorted(feature_scores.items(), key=lambda x: x[1], reverse=True)
fig, ax = plt.subplots(figsize=(10, 10))
ax.barh(range(len(sorted_scores)), [score[1] for score in sorted_scores])
ax.set_yticks(range(len(sorted_scores)))
ax.set_yticklabels([score[0] for score in sorted_scores])
ax.set_xlabel('p_value')
ax.set_title('Feature p_value by chi-squared test')
plt.show()