# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/JSJeong-me/KOSA-Big-Data_Vision/blob/main/Preprocessing/0915-regression_feature.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + [markdown] id="olive-decrease"
# ### Regression Feature Selection:
# (Numerical Input, Numerical Output)

# + [markdown] id="saved-values"
# Feature selection is performed using Pearson’s Correlation Coefficient via the f_regression() function.

# + id="political-track"
# pearson's correlation feature selection for numeric input and numeric output
from sklearn.datasets import make_regression
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import f_regression


# + id="adjacent-private"
# generate dataset
X, y = make_regression(n_samples=10000, n_features=500, n_informative=10)


# + id="o81zk1HseJQI" outputId="26cf6f77-322e-494c-915d-dd01ec6c8de1" colab={"base_uri": "https://localhost:8080/"}
X.shape

# + id="vRGDAW9ReMJL" outputId="d6f1f4b4-6033-4277-d12e-4707993d8f98" colab={"base_uri": "https://localhost:8080/"}
X[:3,:]

# + id="gcRwjPwIeMF_" outputId="1a396834-e058-4200-d970-2c85c9c76df9" colab={"base_uri": "https://localhost:8080/"}
y[:3]

# + id="ctXhRxFdeMCQ"


# + id="5e5wB46CdjUB"
# define feature selection
fs = SelectKBest(score_func=f_regression, k=50)
# apply feature selection


# + id="OL1v9R0ge4Ss" outputId="a9c8b7d7-dac7-4bd0-a96a-dbcacb2397d1" colab={"base_uri": "https://localhost:8080/"}
X_selected = fs.fit_transform(X, y)
print(X_selected.shape)

# + id="7b7BooQGfLaI" outputId="bf6af650-aa0d-4623-e88d-4b8a0b99273f" colab={"base_uri": "https://localhost:8080/"}
X_selected.shape

# + id="4-9tw8m8fixK" outputId="2e0835c1-4675-44f1-ab0b-c2534686f1b2" colab={"base_uri": "https://localhost:8080/"}
type(X_selected)

# + id="miQ1m6gofyMZ"
import pandas as pd

# + id="lFf0M0o5gDvh"
df_y = pd.DataFrame(y) 

# + id="mmoP4dGSfisq"
df = pd.DataFrame(X_selected)

# + id="ddiRj6-rgSwm"


# + id="RprnxHQsfijI" outputId="70fdc7ef-7687-45db-d1a5-cad8dd22c9d2" colab={"base_uri": "https://localhost:8080/", "height": 516}
df.corr().round()

# + id="spjnlqq2fiWq"


StarcoderdataJupyterScriptsDedupFiltered