Upload _1393.py
Browse files
_1393.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
""".1393
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colab.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1-65IULC0-UxJ7kZBDYo3KQ2a6m5JzwVV
|
| 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 (2).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('Employment 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 |
+
plt.title('Top 10 Industries by Job Postings')
|
| 37 |
+
plt.show()
|
| 38 |
+
|
| 39 |
+
df.fillna('Unknown', inplace=True)
|
| 40 |
+
df['fraudulent'] = df['fraudulent'].astype(int)
|
| 41 |
+
|
| 42 |
+
df['description_length'] = df['requirements'].apply(lambda x: len(x.split(',')))
|
| 43 |
+
|
| 44 |
+
from sklearn.model_selection import train_test_split
|
| 45 |
+
from sklearn.linear_model import LogisticRegression
|
| 46 |
+
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
|
| 47 |
+
|
| 48 |
+
# Select features and target
|
| 49 |
+
features = ['description_length', 'num_requirements']
|
| 50 |
+
X = df[features]
|
| 51 |
+
y = df['fraudulent']
|
| 52 |
+
|
| 53 |
+
# Ensure there are at least two classes in the target variable
|
| 54 |
+
if len(y.unique()) < 2:
|
| 55 |
+
print("The target variable 'fraudulent' must have at least two classes. Exiting...")
|
| 56 |
+
else:
|
| 57 |
+
# Split the data
|
| 58 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 59 |
+
|
| 60 |
+
# Train the model
|
| 61 |
+
model = LogisticRegression()
|
| 62 |
+
model.fit(X_train, y_train)
|