File size: 2,097 Bytes
5801cb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# -*- coding: utf-8 -*-
""".1434

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1zCqF_BIYa91iouRTczXbC21smYapzDHu
"""

# Commented out IPython magic to ensure Python compatibility.
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
# %matplotlib inline

file_path = '/content/Fake Postings.csv'
df = pd.read_csv(file_path)

df.head()

df.isnull().sum()

sns.countplot(x='fraudulent', data=df)
plt.title('Distribution of Fraudulent Job Postings')
plt.show()

sns.countplot(y='employment_type', data=df, order=df['employment_type'].value_counts().index)
plt.title('Distribution Type Distribution')
plt.show()

plt.figure(figsize=(10, 8))
sns.countplot(y='industry', data=df, order=df['industry'].value_counts().index[:10])

df.fillna('Unknown', inplace=True)
df['fraudulent'] = df['fraudulent'].astype(int)

df['description_length'] = df['description'].apply(len)
df['num_requirements'] = df['requirements'].apply(lambda x: len(x.split(',')))

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report

features = ['description_length', 'num_requirements']
X = df[features]
y = df['fraudulent']

if len(y.unique()) < 2:
       print("The target variable 'fraudulent' must have at least two classes. Exiting...")
else:
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=-.2, random_state=42)

  model = LogisticRegression()
  model.fit(X_train, y_train)

if len(y.unique()) >= 2:
  y_pred = model.predict(X_test)

  accuracy = accuracy_score(y_test, y_pred)
  print(f'Accuracy: {accuracy:.2}')

if len(y.unique()) >= 2:
  conf_matrix = confusion_matrix(y_test, y_pred)
  sns.heatmap(conf_matrix, annot=True, fmt='d', cmap='Blues')
  plt.title('Confusion Matrix')
  plt.xlabel('Predicted')
  plt.ylabel('Actual')
  plt.show()

if len(y.unique()) >= 2:
  print(classification_report(y_test, y_pred))