I am trying to check the correlation in a red wine quality dataset via a scatter plot but it seems it just doesn't seem to be linear.
I have applied the preprocessing steps below:
- Standard Scaler since the range was different for all the columns.
- Treated outliers
So the standard scaler code is as below:
df_red = pd.read_csv('wine+quality/winequality-red.csv', sep=';')
def preprocess_data(df): # Trying to scale the data since columns likely have different ranges.
res_df = df.copy()
std = StandardScaler()
for i in list(res_df.columns):
res_df[i]= std.fit_transform(res_df[[i]].values)
return res_df
encoded_df = preprocess_data(df_red)
Original data:
Data looks like the below after applying the standard scaler:
Where quality
is the target variable.
Now below is my code for treating outliers:
Q1 = encoded_df['fixed acidity'].quantile(0.25)
Q3 = encoded_df['fixed acidity'].quantile(0.75)
IQR = Q3 - Q1
LL = Q1 - 1.5 * IQR
UL = Q3 + 1.5 * IQR
ul_outlier_count = encoded_df[encoded_df['fixed acidity'] > UL].shape[0]
ll_outlier_count = encoded_df[encoded_df['fixed acidity'] < LL].shape[0]
total_outliers = ul_outlier_count + ll_outlier_count
perc_outliers = total_outliers * 100 / encoded_df.shape[0]
print(f'UL Outlier Count: {ul_outlier_count} | LL Outlier Count: {ll_outlier_count} | Total Outlier Count: {total_outliers} | Outlier%: {perc_outliers}')
#since my outliers are less than 5%
encoded_df.loc[encoded_df['fixed acidity'] > UL] = UL
encoded_df.loc[encoded_df['fixed acidity'] < LL] = LL
So below is my boxplot before treating outliers:
Below is my boxplot after treating outliers:
I have used a pair plot to identify which feature is strongly correlated with the target so that I can use that feature for training the model.
By looking at this pair plot can I say that the data is not fit for linear regression? Since the data is not fit for linear regression it would also not be fit for logistic regression, as in logistic regression we need to create a linear regression model first and then pass that model to the sigmoid
function/logit
function internally.
Or do I need to get more features for the training? I don't think the features are anywhere related to the target.