<jupyter_start><jupyter_text>Campus Placement DataThis data set consists of Placement data of students in a college of India. It includes secondary and higher secondary school percentage and specialization. It also includes degree specialization, type and Work experience and salary offers to the placed students. Business UnderStanding :Does GPA affect placement?Does Higher Secondary School's Percentage still affect campus placement?Is work experience required for securing good job?    What factor affect the salary?<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import pandas_profiling
data = pd.read_csv("Placement_Data.csv")

"""
Description: Read a comma-separated values (csv) file into DataFrame.

Arguments:
    filepath_or_buffer : str, path object or file-like object
    Any valid string path is acceptable. The string could be a 
    URL. Valid URL schemes include http, ftp, s3, and file.

Returns:
    DataFrame or TextParser
    A comma-separated values (csv) file is returned as two
    -dimensional data structure with labeled axes.
"""

data.drop("sl_no", axis=1, inplace=True)


"""
Description: Remove rows or columns by specifying label names 
             and corresponding axis, or by specifying directly 
             index or column names.

Arguments:
    labels : single label or list-like Index or column labels to 
             drop.

    axis : {0 or ‘index’, 1 or ‘columns’}, default 0
           Whether to drop labels from the index (0 or ‘index’) 
           or columns (1 or ‘columns’).
           
    inplace : bool, default False If True, do operation inplace 
              and return None.

Returns:
   DataFrame
DataFrame without the removed index or column labels.

"""

data.head()


"""
Description: Return the first n rows.

Parameters :
      n : int, default 5 Number of rows to select.

Returns:
    same type as caller
The first n rows of the caller object.

"""
#pre-processing data
data.isnull().sum()
#only salary has null values 
#67 people are unplaced
data['salary']=data['salary'].fillna(0).astype(float)
data.head() 
"""
Description: Return the first n rows.

Parameters :
      n : int, default 5 Number of rows to select.

Returns:
    same type as caller
The first n rows of the caller object.

"""<jupyter_output><empty_output><jupyter_text>Exploring Data by each Features Does gender affect placements?<jupyter_code>data.gender.value_counts()
sns.countplot("gender", hue="status", data=data)
"""
Description: A count plot can be thought of as a histogram across a 
categorical, instead of quantitative, variable. The basic API and 
options are identical to those for barplot(), so you can compare 
counts across nested variables.

Arguments:
    x, y, hue : names of variables in data or vector data, optional
                Inputs for plotting long-form data.

    data: DataFrame, array, or list of arrays, optional
          Dataset for plotting. If x and y are absent, 
          this is interpreted as wide-form. 
          Otherwise it is expected to be long-form. 

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()
data.groupby(['gender','status'])['status'].count().plot.line()
"""
Description: Group DataFrame using a mapper or by a Series of columns.

Arguments:
    by : mapping, function, label, or list of labels

    axis : {0 or ‘index’, 1 or ‘columns’}, default 0
           Split along rows (0) or columns (1).

Returns:
    DataFrameGroupBy
    Returns a groupby object that contains information about the groups.
"""
sns.kdeplot(data.salary[ data.gender=="M"])
"""
Description: Fit and plot a univariate or bivariate kernel density estimate.

Arguments:
    data : 1d array-likeInput data.

    data2 : 1d array-like, optional Second input data. 
    If present, a bivariate KDE will be estimated

Returns:
    ax : matplotlib Axes
    Axes with plot.
"""
sns.kdeplot(data.salary[ data.gender=="F"])
plt.legend(["Male", "Female"])
plt.xlabel("Salary (100k)")
plt.show()
plt.figure(figsize =(18,6))
sns.boxplot("salary", "gender", data=data)
"""
Description: Draw a box plot to show distributions with respect to categories.

Arguments:
    x, y, hue :names of variables in data or vector data, optional
    Inputs for plotting long-form data. See examples for interpretation.

    data : DataFrame, array, or list of arrays, optional
    Dataset for plotting. If x and y are absent, this is 
    interpreted as wide-form. Otherwise it is expected to 
    be long-form.

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output><empty_output><jupyter_text>Conclusion:    We have samples of 139 Male studets and 76 Female students.    30 Female and 40 Male students are not placed. Male students have comparatively higher placemets.    More outliers on Male -> Male students are getting high CTC jobs.    Male students are offered slightly greater salary than female on an average. Does Secondary Education affect placements?<jupyter_code>sns.kdeplot(data.ssc_p[ data.status=="Placed"])
"""
Description: Fit and plot a univariate or bivariate kernel density estimate.

Arguments:
    data : 1d array-likeInput data.

    data2 : 1d array-like, optional Second input data. 
    If present, a bivariate KDE will be estimated

Returns:
    ax : matplotlib Axes
    Axes with plot.
"""
sns.kdeplot(data.ssc_p[ data.status=="Not Placed"])
plt.legend(["Placed", "Not Placed"])
plt.xlabel("Secondary Education Percentage")
plt.show()<jupyter_output>C:\Users\KIIT\AppData\Roaming\Python\Python37\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval<jupyter_text>All students with Secondary Education Percentage above 90% are placedAll students with Secondary Education Percentage below 50% are not-placedStudents with good Secondary Education Percentage are placed on average.<jupyter_code>sns.countplot("ssc_b", hue="status", data=data)
"""
Description: A count plot can be thought of as a histogram across a 
categorical, instead of quantitative, variable. The basic API and 
options are identical to those for barplot(), so you can compare 
counts across nested variables.

Arguments:
    x, y, hue : names of variables in data or vector data, optional
                Inputs for plotting long-form data.

    data: DataFrame, array, or list of arrays, optional
          Dataset for plotting. If x and y are absent, 
          this is interpreted as wide-form. 
          Otherwise it is expected to be long-form. 

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output><empty_output><jupyter_text>Board Of Education does not affect Placement Status much<jupyter_code>plt.figure(figsize =(18,6))
sns.boxplot("salary", "ssc_b", data=data)
"""
Description: Draw a box plot to show distributions with respect to categories.

Arguments:
    x, y, hue :names of variables in data or vector data, optional
    Inputs for plotting long-form data. See examples for interpretation.

    data : DataFrame, array, or list of arrays, optional
    Dataset for plotting. If x and y are absent, this is 
    interpreted as wide-form. Otherwise it is expected to 
    be long-form.

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output><empty_output><jupyter_text>Outliers on both, but students from Central Board are getting the highly paid jobs.<jupyter_code>sns.lineplot("ssc_p", "salary", hue="ssc_b", data=data)
"""
Description: Draw a line plot with possibility of several semantic groupings.

Arguments:
    x, y : names of variables in data or vector data, optional
    Input data variables; must be numeric. Can pass data directly 
    or reference columns in data.

    hue : name of variables in data or vector data, optional
          Grouping variable that will produce lines with different 
          colors. Can be either categorical or numeric, although 
          color mapping will behave differently in latter case.

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output>C:\Users\KIIT\AppData\Roaming\Python\Python37\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval<jupyter_text>No specific pattern (correlation) between Secondary Education Percentage and Salary.Board of Education is Not Affecting Salary Does Higher Secondary School affect Placements?<jupyter_code>sns.kdeplot(data.hsc_p[ data.status=="Placed"])
"""
Description: Fit and plot a univariate or bivariate kernel density estimate.

Arguments:
    data : 1d array-likeInput data.

    data2 : 1d array-like, optional Second input data. 
    If present, a bivariate KDE will be estimated

Returns:
    ax : matplotlib Axes
    Axes with plot.
"""
sns.kdeplot(data.hsc_p[ data.status=="Not Placed"])
plt.legend(["Placed", "Not Placed"])
plt.xlabel("Higher Secondary Education Percentage")
plt.show()<jupyter_output><empty_output><jupyter_text>Overlap here too. More placements for percentage above 65%Straight drop below 60 in placements -> Perntage must be atleast 60 for chance of being placed<jupyter_code>sns.countplot("hsc_b", hue="status", data=data)
"""
Description: A count plot can be thought of as a histogram across a 
categorical, instead of quantitative, variable. The basic API and 
options are identical to those for barplot(), so you can compare 
counts across nested variables.

Arguments:
    x, y, hue : names of variables in data or vector data, optional
                Inputs for plotting long-form data.

    data: DataFrame, array, or list of arrays, optional
          Dataset for plotting. If x and y are absent, 
          this is interpreted as wide-form. 
          Otherwise it is expected to be long-form. 

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output><empty_output><jupyter_text>Education Board again, doesn't affect placement status much<jupyter_code>sns.countplot("hsc_s", hue="status", data=data)
"""
Description: A count plot can be thought of as a histogram across a 
categorical, instead of quantitative, variable. The basic API and 
options are identical to those for barplot(), so you can compare 
counts across nested variables.

Arguments:
    x, y, hue : names of variables in data or vector data, optional
                Inputs for plotting long-form data.

    data: DataFrame, array, or list of arrays, optional
          Dataset for plotting. If x and y are absent, 
          this is interpreted as wide-form. 
          Otherwise it is expected to be long-form. 

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output><empty_output><jupyter_text>We have very less students with Arts specialization.Around 2:1 placed:unplaced ratio for both Science and Commerse students<jupyter_code>plt.figure(figsize =(18,6))
sns.boxplot("salary", "hsc_b", data=data)
"""
Description: Draw a box plot to show distributions with respect to categories.

Arguments:
    x, y, hue :names of variables in data or vector data, optional
    Inputs for plotting long-form data. See examples for interpretation.

    data : DataFrame, array, or list of arrays, optional
    Dataset for plotting. If x and y are absent, this is 
    interpreted as wide-form. Otherwise it is expected to 
    be long-form.

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output><empty_output><jupyter_text>Outliers on both, board doesn't affect getting highly paid jobs. Highest paid job was obtailed by student from Central Board though.<jupyter_code>sns.lineplot("hsc_p", "salary", hue="hsc_b", data=data)
"""
Description: Draw a line plot with possibility of several semantic groupings.

Arguments:
    x, y : names of variables in data or vector data, optional
    Input data variables; must be numeric. Can pass data directly 
    or reference columns in data.

    hue : name of variables in data or vector data, optional
          Grouping variable that will produce lines with different 
          colors. Can be either categorical or numeric, although 
          color mapping will behave differently in latter case.

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output>C:\Users\KIIT\AppData\Roaming\Python\Python37\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval<jupyter_text>High salary from both Central and Other.High salary for both high and low percentage.Thus, both these feature doesnot affect salary.<jupyter_code>plt.figure(figsize =(18,6))
sns.boxplot("salary", "hsc_s", data=data)
"""
Description: Draw a box plot to show distributions with respect to categories.

Arguments:
    x, y, hue :names of variables in data or vector data, optional
    Inputs for plotting long-form data. See examples for interpretation.

    data : DataFrame, array, or list of arrays, optional
    Dataset for plotting. If x and y are absent, this is 
    interpreted as wide-form. Otherwise it is expected to 
    be long-form.

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output><empty_output><jupyter_text>We can't really say for sure due to only few samples of students with Arts Major, but they aren't getting good salaries.Commerse students have slightly better placement status. Does Under Graduate affect placements?<jupyter_code>sns.kdeplot(data.degree_p[ data.status=="Placed"])
"""
Description: Fit and plot a univariate or bivariate kernel density estimate.

Arguments:
    data : 1d array-likeInput data.

    data2 : 1d array-like, optional Second input data. 
    If present, a bivariate KDE will be estimated

Returns:
    ax : matplotlib Axes
    Axes with plot.
"""
sns.kdeplot(data.degree_p[ data.status=="Not Placed"])
plt.legend(["Placed", "Not Placed"])
plt.xlabel("Under Graduate Percentage")
plt.show()<jupyter_output>C:\Users\KIIT\AppData\Roaming\Python\Python37\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval<jupyter_text>Overlap here too. But More placements for percentage above 65.UG Percentage least 50% to get placement<jupyter_code>sns.countplot("degree_t", hue="status", data=data)
"""
Description: A count plot can be thought of as a histogram across a 
categorical, instead of quantitative, variable. The basic API and 
options are identical to those for barplot(), so you can compare 
counts across nested variables.

Arguments:
    x, y, hue : names of variables in data or vector data, optional
                Inputs for plotting long-form data.

    data: DataFrame, array, or list of arrays, optional
          Dataset for plotting. If x and y are absent, 
          this is interpreted as wide-form. 
          Otherwise it is expected to be long-form. 

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output><empty_output><jupyter_text>We have very less students with "Other". We cant make decision from few cases.Around 2:1 placed:unplaced ratio for both Science and Commerse students<jupyter_code>plt.figure(figsize =(18,6))
sns.boxplot("salary", "degree_t", data=data)
"""
Description: Draw a box plot to show distributions with respect to categories.

Arguments:
    x, y, hue :names of variables in data or vector data, optional
    Inputs for plotting long-form data. See examples for interpretation.

    data : DataFrame, array, or list of arrays, optional
    Dataset for plotting. If x and y are absent, this is 
    interpreted as wide-form. Otherwise it is expected to 
    be long-form.

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output><empty_output><jupyter_text>Science&Tech students getting more salary on averageManagement stidents are getting more highly paid dream jobs. Does Work Experience affect placements?<jupyter_code>sns.countplot("workex", hue="status", data=data)
"""
Description: A count plot can be thought of as a histogram across a 
categorical, instead of quantitative, variable. The basic API and 
options are identical to those for barplot(), so you can compare 
counts across nested variables.

Arguments:
    x, y, hue : names of variables in data or vector data, optional
                Inputs for plotting long-form data.

    data: DataFrame, array, or list of arrays, optional
          Dataset for plotting. If x and y are absent, 
          this is interpreted as wide-form. 
          Otherwise it is expected to be long-form. 

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output><empty_output><jupyter_text>This affects Placement. Very few students with work experience not getting placed!<jupyter_code>plt.figure(figsize =(18,6))
sns.boxplot("salary", "workex", data=data)
"""
Description: Draw a box plot to show distributions with respect to categories.

Arguments:
    x, y, hue :names of variables in data or vector data, optional
    Inputs for plotting long-form data. See examples for interpretation.

    data : DataFrame, array, or list of arrays, optional
    Dataset for plotting. If x and y are absent, this is 
    interpreted as wide-form. Otherwise it is expected to 
    be long-form.

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output><empty_output><jupyter_text>Outliers (High salary than average) on bith end but students with experience getting dream jobsAverage salary as well as base salary high for students with work experience.<jupyter_code>sns.kdeplot(data.etest_p[ data.status=="Placed"])
"""
Description: Fit and plot a univariate or bivariate kernel density estimate.

Arguments:
    data : 1d array-likeInput data.

    data2 : 1d array-like, optional Second input data. 
    If present, a bivariate KDE will be estimated

Returns:
    ax : matplotlib Axes
    Axes with plot.
"""
sns.kdeplot(data.etest_p[ data.status=="Not Placed"])
plt.legend(["Placed", "Not Placed"])
plt.xlabel("Employability test percentage")
plt.show()<jupyter_output>C:\Users\KIIT\AppData\Roaming\Python\Python37\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval<jupyter_text>Post Graduate Specialization<jupyter_code>sns.countplot("specialisation", hue="status", data=data)
"""
Description: A count plot can be thought of as a histogram across a 
categorical, instead of quantitative, variable. The basic API and 
options are identical to those for barplot(), so you can compare 
counts across nested variables.

Arguments:
    x, y, hue : names of variables in data or vector data, optional
                Inputs for plotting long-form data.

    data: DataFrame, array, or list of arrays, optional
          Dataset for plotting. If x and y are absent, 
          this is interpreted as wide-form. 
          Otherwise it is expected to be long-form. 

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output><empty_output><jupyter_text>his feature affects Placement status.Comparitively very low not-placed students in Mkt&Fin Section Does MBA Percentage affect placements?<jupyter_code>sns.boxplot("mba_p", "status", data=data)
"""
Description: Draw a box plot to show distributions with respect to categories.

Arguments:
    x, y, hue :names of variables in data or vector data, optional
    Inputs for plotting long-form data. See examples for interpretation.

    data : DataFrame, array, or list of arrays, optional
    Dataset for plotting. If x and y are absent, this is 
    interpreted as wide-form. Otherwise it is expected to 
    be long-form.

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()
sns.lineplot("mba_p", "salary", data=data)
"""
Description: Draw a line plot with possibility of several semantic groupings.

Arguments:
    x, y : names of variables in data or vector data, optional
    Input data variables; must be numeric. Can pass data directly 
    or reference columns in data.

    hue : name of variables in data or vector data, optional
          Grouping variable that will produce lines with different 
          colors. Can be either categorical or numeric, although 
          color mapping will behave differently in latter case.

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.
"""
plt.show()<jupyter_output>C:\Users\KIIT\AppData\Roaming\Python\Python37\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval<jupyter_text>MBA Percentage also deos not affect salary much  Data Pre-Processing<jupyter_code>data.drop(['ssc_b','hsc_b'], axis=1, inplace=True)<jupyter_output><empty_output><jupyter_text>Feature Encoding<jupyter_code>data.dtypes
data["gender"] = data.gender.map({"M":0,"F":1})
data["hsc_s"] = data.hsc_s.map({"Commerce":0,"Science":1,"Arts":2})
data["degree_t"] = data.degree_t.map({"Comm&Mgmt":0,"Sci&Tech":1, "Others":2})
data["workex"] = data.workex.map({"No":0, "Yes":1})
data["status"] = data.status.map({"Not Placed":0, "Placed":1})
data["specialisation"] = data.specialisation.map({"Mkt&HR":0, "Mkt&Fin":1})<jupyter_output><empty_output><jupyter_text>Problem StatementPredicting If Students gets placed or not (Binary Classification Problem)<jupyter_code># Library imports
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, classification_report
data_clf = data.copy()
data_reg = data.copy()
X = data_clf[['gender', 'ssc_p', 'hsc_p', 'hsc_s', 'degree_p', 'degree_t', 'workex','etest_p', 'specialisation', 'mba_p',]]
y = data_clf['status']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
dtree = DecisionTreeClassifier(criterion='entropy')
dtree.fit(X_train, y_train)
y_pred = dtree.predict(X_test)
accuracy_score(y_test, y_pred)
print(classification_report(y_test, y_pred))
#Using Random Forest Algorithm
random_forest = RandomForestClassifier(n_estimators=100)
random_forest.fit(X_train, y_train)
y_pred = random_forest.predict(X_test)
accuracy_score(y_test, y_pred)
print(classification_report(y_test, y_pred))<jupyter_output>precision    recall  f1-score   support

           0       0.63      0.67      0.65        18
           1       0.87      0.85      0.86        47

    accuracy                           0.80        65
   macro avg       0.75      0.76      0.75        65
weighted avg       0.80      0.80      0.80        65<jupyter_text>Feature Importance (Percentage)Tree based algorithms can be used to compute feature importanceChecking feature importance obtained from these:<jupyter_code>rows = list(X.columns)
imp = pd.DataFrame(np.zeros(6*len(rows)).reshape(2*len(rows), 3))
imp.columns = ["Classifier", "Feature", "Importance"]
#Add Rows
for index in range(0, 2*len(rows), 2):
    imp.iloc[index] = ["DecisionTree", rows[index//2], (100*dtree.feature_importances_[index//2])]
    imp.iloc[index + 1] = ["RandomForest", rows[index//2], (100*random_forest.feature_importances_[index//2])]
plt.figure(figsize=(15,5))
sns.barplot("Feature", "Importance", hue="Classifier", data=imp)

"""
Description: Show point estimates and confidence intervals as rectangular bars.

Parameters:
    x, y, hue : names of variables in data or vector data, optional Inputs for 
                plotting long-form data. See examples for interpretation.

    data : DataFrame, array, or list of arrays, optional Dataset for plotting. 
           If x and y are absent, this is interpreted as wide-form. Otherwise it 
           is expected to be long-form.

Returns:
    ax : matplotlib Axes
    Returns the Axes object with the plot drawn onto it.

"""
plt.title("Computed Feature Importance")
plt.show()<jupyter_output><empty_output><jupyter_text>hsc_s -> Specialization in Higher Secondary Educationdegree_t -> Under Graduation(Degree type)- Field of degree educationspecialisation -> Post Graduation(MBA)- Specialization  Field of study does not seem to affect much One Hot Encoding<jupyter_code># Seperating Features and Target
X = data_clf[['gender', 'ssc_p', 'hsc_p', 'hsc_s', 'degree_p', 'degree_t', 'workex','etest_p', 'specialisation', 'mba_p',]]
y = data_clf['status']
#Reverse Mapping and making Categorical
X["gender"] = pd.Categorical(X.gender.map({0:"M",1:"F"}))
X["hsc_s"] = pd.Categorical(X.hsc_s.map({0:"Commerce",1:"Science",2:"Arts"}))
X["degree_t"] = pd.Categorical(X.degree_t.map({0:"Comm&Mgmt",1:"Sci&Tech",2:"Others"}))
X["workex"] = pd.Categorical(X.workex.map({0:"No",1:"Yes"}))
X["specialisation"] = pd.Categorical(X.specialisation.map({0:"Mkt&HR",1:"Mkt&Fin"}))
#One-Hot Encoding
X = pd.get_dummies(X)
colmunn_names = X.columns.to_list()<jupyter_output><empty_output><jupyter_text>Feature Scaling:    Percentages are on scale 0-100Categorical Features are on range 0-1 (By one hot encoding)High Scale for Salary -> Salary is heavily skewed too -> SkLearn has RobustScaler which might work well hereScaling Everything between 0 and 1 (This wont affect one-hot encoded values)<jupyter_code>from sklearn.preprocessing import MinMaxScaler
from sklearn.linear_model import LogisticRegression

scaler = MinMaxScaler()
X_scaled = scaler.fit_transform(X)
#Train Test Split
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.3)

logistic_reg = LogisticRegression()



logistic_reg.fit(X_train, y_train)

"""
Description: Build a decision tree classifier from the training set (X, y).

Parameters:
    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        The training input samples. Internally, it will be converted 
        to dtype=np.float32 and if a sparse matrix is provided to a
        sparse csc_matrix.

    y : array-like of shape (n_samples,) or (n_samples, n_outputs)
        The target values (class labels) as integers or strings.

Returns:
   self : DecisionTreeClassifier
          Fitted estimator.

"""

y_pred = logistic_reg.predict(X_test)

accuracy_score(y_test, y_pred)
print(classification_report(y_test, y_pred))<jupyter_output>precision    recall  f1-score   support

           0       0.94      0.64      0.76        25
           1       0.81      0.97      0.89        40

    accuracy                           0.85        65
   macro avg       0.88      0.81      0.82        65
weighted avg       0.86      0.85      0.84        65<jupyter_text>Computating Feature importance by Mean Decrease Accuracy (MDA)<jupyter_code>#pip install eli5
import eli5
from eli5.sklearn import PermutationImportance
perm = PermutationImportance(logistic_reg).fit(X_test, y_test)
eli5.show_weights(perm)
plt.figure(figsize=(30, 10))
plt.bar(colmunn_names , perm.feature_importances_std_ * 100)
"""
Description: Make a bar plot. The bars are positioned at x with the given alignment. 
             Their dimensions are given by width and height. The vertical baseline is 
             bottom (default 0).

Parameters:
     x : sequence of scalars The x coordinates of the bars. See also align for the 
     alignment of the bars to the coordinates.

     height : scalar or sequence of scalars The height(s) of the bars.

     width : scalar or array-like, optional The width(s) of the bars (default: 0.8).

Returns:
   container : BarContainer
 Container with all the bars and optionally errorbars.

"""
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08798059103009065, 'fraction_numerical': 0.010041446237827274, 'mean_word_length': 3.9753562447611066, 'pattern_counts': {'":': 14, '<': 101, '<?xml version=': 0, '>': 108, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '27', 'dir': 'jupyter-structured-clean-dedup', 'id': '343846', 'license': 'MIT', 'n_tokens_mistral': 9198, 'n_tokens_neox': 8611, 'n_words': 3361, 'path': 'Placement Data Analysis.ipynb', 'repo_name': 'Toulik-Das/Placement-Data-Analysis', 'size': '29677'}