harshiv commited on
Commit
2b2aa8f
·
1 Parent(s): fb33d3b

Upload Untitled2.ipynb

Browse files
Files changed (1) hide show
  1. Untitled2.ipynb +104 -0
Untitled2.ipynb ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "id": "2a0f61a3",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "Accuracy: 0.8417508417508418\n"
14
+ ]
15
+ }
16
+ ],
17
+ "source": [
18
+ "import pandas as pd\n",
19
+ "from sklearn.compose import ColumnTransformer\n",
20
+ "from sklearn.ensemble import RandomForestClassifier\n",
21
+ "from sklearn.impute import SimpleImputer\n",
22
+ "from sklearn.model_selection import train_test_split\n",
23
+ "from sklearn.pipeline import Pipeline\n",
24
+ "from sklearn.preprocessing import LabelEncoder, StandardScaler\n",
25
+ "\n",
26
+ "# Load the CSV data\n",
27
+ "data = pd.read_csv('dataset.csv')\n",
28
+ "\n",
29
+ "# Split the data into features and labels\n",
30
+ "X = data.drop('PlacedOrNot', axis=1)\n",
31
+ "y = data['PlacedOrNot']\n",
32
+ "\n",
33
+ "# Encode categorical features\n",
34
+ "categorical_features = ['HistoryOfBacklogs']\n",
35
+ "for feature in categorical_features:\n",
36
+ " encoder = LabelEncoder()\n",
37
+ " X[feature] = encoder.fit_transform(X[feature])\n",
38
+ "\n",
39
+ "# Split the data into training and testing sets\n",
40
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
41
+ "\n",
42
+ "# Create the pipeline\n",
43
+ "numerical_features = ['Internships', 'CGPA']\n",
44
+ "numerical_transformer = StandardScaler()\n",
45
+ "categorical_features = [ 'HistoryOfBacklogs']\n",
46
+ "categorical_transformer = SimpleImputer(strategy='most_frequent')\n",
47
+ "preprocessor = ColumnTransformer(\n",
48
+ " transformers=[\n",
49
+ " ('num', numerical_transformer, numerical_features),\n",
50
+ " ('cat', categorical_transformer, categorical_features)\n",
51
+ " ])\n",
52
+ "\n",
53
+ "pipeline = Pipeline([\n",
54
+ " ('preprocessor', preprocessor),\n",
55
+ " ('classifier', RandomForestClassifier(random_state=42))\n",
56
+ "])\n",
57
+ "\n",
58
+ "# Train the model\n",
59
+ "pipeline.fit(X_train, y_train)\n",
60
+ "\n",
61
+ "# Evaluate the model\n",
62
+ "accuracy = pipeline.score(X_test, y_test)\n",
63
+ "print('Accuracy:', accuracy)\n"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": null,
69
+ "id": "8e941b77",
70
+ "metadata": {},
71
+ "outputs": [],
72
+ "source": []
73
+ },
74
+ {
75
+ "cell_type": "code",
76
+ "execution_count": null,
77
+ "id": "4a2788a3",
78
+ "metadata": {},
79
+ "outputs": [],
80
+ "source": []
81
+ }
82
+ ],
83
+ "metadata": {
84
+ "kernelspec": {
85
+ "display_name": "Python 3 (ipykernel)",
86
+ "language": "python",
87
+ "name": "python3"
88
+ },
89
+ "language_info": {
90
+ "codemirror_mode": {
91
+ "name": "ipython",
92
+ "version": 3
93
+ },
94
+ "file_extension": ".py",
95
+ "mimetype": "text/x-python",
96
+ "name": "python",
97
+ "nbconvert_exporter": "python",
98
+ "pygments_lexer": "ipython3",
99
+ "version": "3.9.12"
100
+ }
101
+ },
102
+ "nbformat": 4,
103
+ "nbformat_minor": 5
104
+ }