Upload _1434.py
Browse files
_1434.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
""".1434
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1zCqF_BIYa91iouRTczXbC21smYapzDHu
|
8 |
+
"""
|
9 |
+
|
10 |
+
# Commented out IPython magic to ensure Python compatibility.
|
11 |
+
import pandas as pd
|
12 |
+
import numpy as np
|
13 |
+
import seaborn as sns
|
14 |
+
import matplotlib.pyplot as plt
|
15 |
+
import warnings
|
16 |
+
warnings.filterwarnings('ignore')
|
17 |
+
# %matplotlib inline
|
18 |
+
|
19 |
+
file_path = '/content/Fake Postings.csv'
|
20 |
+
df = pd.read_csv(file_path)
|
21 |
+
|
22 |
+
df.head()
|
23 |
+
|
24 |
+
df.isnull().sum()
|
25 |
+
|
26 |
+
sns.countplot(x='fraudulent', data=df)
|
27 |
+
plt.title('Distribution of Fraudulent Job Postings')
|
28 |
+
plt.show()
|
29 |
+
|
30 |
+
sns.countplot(y='employment_type', data=df, order=df['employment_type'].value_counts().index)
|
31 |
+
plt.title('Distribution Type Distribution')
|
32 |
+
plt.show()
|
33 |
+
|
34 |
+
plt.figure(figsize=(10, 8))
|
35 |
+
sns.countplot(y='industry', data=df, order=df['industry'].value_counts().index[:10])
|
36 |
+
|
37 |
+
df.fillna('Unknown', inplace=True)
|
38 |
+
df['fraudulent'] = df['fraudulent'].astype(int)
|
39 |
+
|
40 |
+
df['description_length'] = df['description'].apply(len)
|
41 |
+
df['num_requirements'] = df['requirements'].apply(lambda x: len(x.split(',')))
|
42 |
+
|
43 |
+
from sklearn.model_selection import train_test_split
|
44 |
+
from sklearn.linear_model import LogisticRegression
|
45 |
+
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
|
46 |
+
|
47 |
+
features = ['description_length', 'num_requirements']
|
48 |
+
X = df[features]
|
49 |
+
y = df['fraudulent']
|
50 |
+
|
51 |
+
if len(y.unique()) < 2:
|
52 |
+
print("The target variable 'fraudulent' must have at least two classes. Exiting...")
|
53 |
+
else:
|
54 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=-.2, random_state=42)
|
55 |
+
|
56 |
+
model = LogisticRegression()
|
57 |
+
model.fit(X_train, y_train)
|
58 |
+
|
59 |
+
if len(y.unique()) >= 2:
|
60 |
+
y_pred = model.predict(X_test)
|
61 |
+
|
62 |
+
accuracy = accuracy_score(y_test, y_pred)
|
63 |
+
print(f'Accuracy: {accuracy:.2}')
|
64 |
+
|
65 |
+
if len(y.unique()) >= 2:
|
66 |
+
conf_matrix = confusion_matrix(y_test, y_pred)
|
67 |
+
sns.heatmap(conf_matrix, annot=True, fmt='d', cmap='Blues')
|
68 |
+
plt.title('Confusion Matrix')
|
69 |
+
plt.xlabel('Predicted')
|
70 |
+
plt.ylabel('Actual')
|
71 |
+
plt.show()
|
72 |
+
|
73 |
+
if len(y.unique()) >= 2:
|
74 |
+
print(classification_report(y_test, y_pred))
|