-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfaml
30 lines (24 loc) · 973 Bytes
/
cfaml
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
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
def train_crime_prediction_model(crime_data):
# Prepare the data
df = pd.DataFrame(crime_data)
X = df[['feature1', 'feature2']] # Replace with actual features
y = df['crime_type']
# Split data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
# Train the model
model = RandomForestClassifier(n_estimators=100)
model.fit(X_train, y_train)
# Evaluate the model
y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
print(f'Model Accuracy: {accuracy:.2f}')
# Example usage
crime_data = [
{'feature1': 1, 'feature2': 2, 'crime_type': 'theft'},
{'feature1': 3, 'feature2': 4, 'crime_type': 'assault'},
# Add more data
]
train_crime_prediction_model(crime_data)