<jupyter_start><jupyter_text>Generating DataSetthe dataset we are generating is just a simulation where we suppose to analyze the employees, we could assume that the level of education, the time spent in the current position and the age are mutually independent and consider them as inputs. Salary and promotion possibilities could be the outputs that depend on the inputs.just for the sake of practice in this notebook we're going to create  a simple model with one feature as an example in which we estimate the salary as a function of ages<jupyter_code>from sklearn.datasets import make_regression
from sklearn.preprocessing import MinMaxScaler
x, y = make_regression(n_samples=100, n_features=1, noise=10, random_state=33)

y_scaler = MinMaxScaler(feature_range=(20, 110))
x_scaler = MinMaxScaler(feature_range=(18,65))

y = y_scaler.fit_transform(y.reshape(-1,1))
x = x_scaler.fit_transform(x.reshape(-1,1))<jupyter_output><empty_output><jupyter_text>Linear RegressionSupervised machine learning algorithms analyze a number of observations and try to mathematically express the dependence between the inputs and outputs. These mathematical representations of dependencies are the models.<jupyter_code>from sklearn.linear_model import LinearRegression

linreg = LinearRegression()
linreg.fit(x,y)
y_pred = linreg.predict(x)
fig, ax1 = plt.subplots()
fig.set_figwidth(8,4)
ax1.plot(x,y, 'o')
ax1.plot(x, y_pred)
ax1.set_xlabel('Age')
ax1.set_ylabel('Income in thousands')<jupyter_output><empty_output><jupyter_text>ClassificationClassification is a very important area of supervised machine learning that tries to predict which class or category some entity belongs to, based on its features.. A large number of important machine learning problems fall within this area. There are many classification methods, and logistic regression is one of them.The features or variables can take one of two forms:1-Independent variables, also called inputs or predictors, don’t depend on other features of interest (or at least you assume so for the purpose of the analysis).2-Dependent variables, also called outputs or responses, depend on the independent variables.  Create a binary version of Y<jupyter_code>y_copy = y.copy()

y_binary = (y_copy > 70).astype(int)
fig, ax1 = plt.subplots()
fig.set_figwidth(8,3)
ax1.scatter(x, y_binary)<jupyter_output><empty_output><jupyter_text>Logistic Regression<jupyter_code>from sklearn.linear_model import LogisticRegression
logreg = LogisticRegression(solver='liblinear')

logreg.fit(x, y_binary.ravel())<jupyter_output><empty_output><jupyter_text>The above statement creates an instance of LogisticRegression and binds its references to the variable model. LogisticRegression has several optional parameters that define the behavior of the model and approach:in our example we're going to use the parameter "solver"SOLVER : is a string ('liblinear' by default) that decides what solver to use for fitting the model. Other options are 'newton-cg', 'lbfgs', 'sag', and 'saga'.<jupyter_code>logreg.classes_<jupyter_output><empty_output><jupyter_text>We can quickly get the attributes of your model. For example, the attribute .classes_ represents the array of distinct values that y takes:   Evaluate the Model<jupyter_code>logreg_pred = logreg.predict_proba(x)
x_predicted[:5]
logreg_pred[:5]<jupyter_output><empty_output><jupyter_text>In the matrix above, each row corresponds to a single observation. The first column is the probability of the predicted output being zero, that is 1 - 𝑝(𝑥). The second column is the probability that the output is one, or 𝑝(𝑥).<jupyter_code>def sigmoid(x):
    return 1 / (1 + np.exp(-x))
x_values = np.arange(x.min(), x.max(), 0.1)
logreg_predicted = logreg.predict_proba(x_values.reshape(-1,1))
fig, ax1 = plt.subplots()
fig.set_figwidth(15,5)

ax1.scatter(x=x, y=y_binary, color='red')
ax1.plot(x_values, logreg_predicted[:,1])<jupyter_output><empty_output><jupyter_text>Evaluating Model PerformanceConfusion Matrix<jupyter_code>from sklearn.metrics import confusion_matrix, plot_confusion_matrix
y_predicted = logreg.predict(x)
conf_mx = confusion_matrix(y_binary, y_predicted)
conf_mx
plot_confusion_matrix(logreg, x, y_binary)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08034026465028356, 'fraction_numerical': 0.012287334593572778, 'mean_word_length': 6.78125, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '376163', 'license': 'MIT', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1287, 'n_words': 442, 'path': 'Supervised Machine Learning/Logistic-Regression.ipynb', 'repo_name': 'akladyous/Machine-Learning', 'size': '4232'}