<jupyter_start><jupyter_text>Polynomial Regression<jupyter_code># import libraries
import matplotlib.pyplot as plt
import numpy as np

# Create X and Y lists
X=[1,2,3,4,5,6,7,8,9,10]
y=[9,10,12,16,22,28,40,58,102,200]

# Plot scatter diagram
plt.scatter(X,y, color = 'red')
plt.title('Polynomial Regression')
plt.xlabel('X-Axis')
plt.ylabel('y-Axis')
# import libraries
import pandas as pd
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression

# Preprare dataset
data = pd.DataFrame({"X":[1,2,3,4,5,6,7,8,9,10],
                     "y":[9,10,12,16,22,28,40,58,102,200]})
X = data[['X']]
y = data[['y']]

# Apply Polynomial Features
polynomial_reg = PolynomialFeatures(degree = 6)
X_polynomial = polynomial_reg.fit_transform(X)

# Apply Linear Regression Model
linear_reg = LinearRegression()
linear_reg.fit(X_polynomial, y)
predictions=linear_reg.predict(X_polynomial)

# plot the results
plt.scatter(X,y, color = 'red')
plt.plot(X, predictions, color = 'blue')
plt.title('Polynomial Regression')
plt.xlabel('X-Axis')
plt.ylabel('y-Axis')
plt.scatter(X,y, color = 'red')
plt.plot(X, predictions, color = 'red')
plt.title('Polynomial Regression')
plt.xlabel('X-Axis')
plt.ylabel('y-Axis')<jupyter_output><empty_output><jupyter_text>Logistic Regression<jupyter_code># Import libraries
import pandas as pd
 
# read the dataset
diabetes = pd.read_csv("diabetes.csv")
 
# Show top 5-records
diabetes.head()
# split dataset in two parts: feature set and target label 
feature_set = ['pregnant', 'insulin', 'bmi', 'age','glucose','bp','pedigree']
features = diabetes[feature_set] 
target = diabetes.label

# partition data into training and testing set 
from sklearn.model_selection import train_test_split
feature_train, feature_test, target_train, target_test = train_test_split(features, target, test_size=0.3, random_state=1)
# import logistic regression scikit-learn model
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score # for performance evaluation
 
# instantiate the model
logreg = LogisticRegression(solver='lbfgs')
 
# fit the model with data
logreg.fit(feature_train,target_train)
 
# Forecast the target variable for given test dataset
predictions = logreg.predict(feature_test)
 
# Assess model performance using accuracy measure
print("Logistic Regression Model Accuracy:",accuracy_score(target_test, predictions))<jupyter_output>Logistic Regression Model Accuracy: 0.7835497835497836
{'fraction_non_alphanumeric': 0.1213338690237043, 'fraction_numerical': 0.03455202892728003, 'mean_word_length': 6.80564263322884, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 8, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '304255', 'license': 'MIT', 'n_tokens_mistral': 921, 'n_tokens_neox': 847, 'n_words': 200, 'path': 'Chapter09/.ipynb_checkpoints/Ch9-checkpoint.ipynb', 'repo_name': 'MichaelCovelli/Python-Data-Analysis-Third-Edition', 'size': '2489'}