<jupyter_start><jupyter_text>Lambda School Data Science*Unit 2, Sprint 1, Module 4*---  Part 1: Sprint Challenge Practice- Can I import a CSV file into a DataFrame?- Can I create a scatter plot?- Can I split a DataFrame into a target vector and feature matrix?- Can I split a dataset into a training set and a test set?- Can I establish the baseline mean absolute error for a regression problem?- Can I combine transformers with a predictor using a pipeline?- Can I build a linear regresion model and a ridge regression model?- Can I evaluate a model using common metrics like mean absolute error, root mean squared error, and R^2?- If given a feature matrix, can I use my model to create a list of predictions?- Can I create a horizontal bar chart with the coefficients from a linear model?  Part 2: Pipelines and PlottingLet's revise [our work from yesterday](https://drive.google.com/file/d/1ZLdUeDkLQNxMJyvbyHfiAvyv-NXPICP9/view?usp=sharing).  Part 3: Logistic Regression  I. Wrangle Data<jupyter_code>def wrangle(filepath):
  df = pd.read_csv(filepath, index_col='PassengerId')
  df.drop(columns=['Name', 'Ticket', 'Cabin'], inplace=True)
  return df

df = wrangle(DATA_PATH+'titanic/train.csv')
X_test = wrangle(DATA_PATH+'titanic/test.csv')
df.info()
X_test.info()<jupyter_output><empty_output><jupyter_text>II. Split Data<jupyter_code># Split TV from our FM
target = 'Survived'
y = df[target]
X = df.drop(columns=target)<jupyter_output><empty_output><jupyter_text>Since there's no time series component, we should do a randomized train-validation split.<jupyter_code># Split our data into a TRAINING set and a VALIDATION set
from sklearn.model_selection import train_test_split

X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42)<jupyter_output><empty_output><jupyter_text>III. Establish our baseline- This is a **classification problem**, so we look at the **majority class** to calculate baseline **accuracy score**.<jupyter_code>print('Baseline Accuracy Score:', y_train.value_counts(normalize=True).max())<jupyter_output>Baseline Accuracy Score: 0.6235955056179775<jupyter_text>IV. Build Model- Why would regular linear regression not work here?<jupyter_code>plt.scatter(X_train['Age'], y_train)
plt.xlabel('Age')
plt.ylabel('Survived?');<jupyter_output><empty_output><jupyter_text>What we need for our model pipeline:- `OneHotEncoder`- `SimpleImputer`- `LogisticRegression`<jupyter_code>model = make_pipeline(
    OneHotEncoder(use_cat_names=True),
    SimpleImputer(),
    LogisticRegression()
)

model.fit(X_train, y_train);<jupyter_output>/usr/local/lib/python3.6/dist-packages/category_encoders/utils.py:21: FutureWarning: is_categorical is deprecated and will be removed in a future version.  Use is_categorical_dtype instead
  elif pd.api.types.is_categorical(cols):
/usr/local/lib/python3.6/dist-packages/sklearn/linear_model/_logistic.py:940: ConvergenceWarning: lbfgs failed to converge (status=1):
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.

Increase the number of iterations (max_iter) or scale the data as shown in:
    https://scikit-learn.org/stable/modules/preprocessing.html
Please also refer to the documentation for alternative solver options:
    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression
  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)<jupyter_text>V. Check Metrics<jupyter_code>print('Training Accuracy:', model.score(X_train, y_train))
print('Validation Accuracy:', model.score(X_val, y_val))
model.predict(X_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10084269662921348, 'fraction_numerical': 0.011235955056179775, 'mean_word_length': 6.312114989733059, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 3, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '604410', 'license': 'MIT', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1163, 'n_words': 338, 'path': 'module4-logistic-regression/2021_02_11_214_guided_project_notes.ipynb', 'repo_name': 'Frank-Howd/DS-Unit-2-Linear-Models', 'size': '3560'}