<jupyter_start><jupyter_text>Regresión Lineal en Python El paquete scikit-learn para regresión lineal y la selección de rasgos<jupyter_code>from sklearn.feature_selection import RFE
from sklearn.svm import SVR
import pandas as pd
import numpy as np
data = pd.read_csv("/Users/nuelcodes/Data-Science-Python/datasets/ads/Advertising.csv")
feature_cols = ["TV", "Radio", "Newspaper"]
# Candidatas a ser variables predictoras
X = data[feature_cols]
# Variable a ser predecida
Y = data["Sales"]
# Queremos estimar un modelo lineal
estimator = SVR(kernel="linear")
# Numero deseador de variables predictoras
selector = RFE(estimator, 2, step=1)
selector = selector.fit(X,Y)
selector.support_
from sklearn.linear_model import LinearRegression
X_pred = X[["TV", "Radio"]]
lm = LinearRegression()
lm.fit(X_pred, Y) # Ajustar las variables predictoras
lm.intercept_ # Donde corta la alpha
lm.coef_ # Coeficientes
lm.score(X_pred, Y) # Obtener el valor de R2 ajustado<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09837728194726167, 'fraction_numerical': 0.0030425963488843813, 'mean_word_length': 6.311111111111111, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '115358', 'license': 'MIT', 'n_tokens_mistral': 356, 'n_tokens_neox': 342, 'n_words': 98, 'path': 'scratch/T4 - 4 - Linear Regression - SciKit-Learn.ipynb', 'repo_name': 'nuelcodes/python-ml-course', 'size': '986'}