Skip to content

Commit 8fbd700

Browse files
committed
add instagram demo
1 parent 872c436 commit 8fbd700

File tree

5 files changed

+1086
-0
lines changed

5 files changed

+1086
-0
lines changed
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"example_data": {
3+
"Number.of.followers": 177,
4+
"Number.of.people.they.follow": 198,
5+
"Number.of.posts": 0,
6+
"Private.account": true,
7+
"has_profile_picture": true,
8+
"rating": false
9+
},
10+
"schema": {
11+
"properties": {
12+
"Number.of.followers": {
13+
"type": [
14+
"integer"
15+
]
16+
},
17+
"Number.of.people.they.follow": {
18+
"type": [
19+
"integer"
20+
]
21+
},
22+
"Number.of.posts": {
23+
"type": [
24+
"integer"
25+
]
26+
},
27+
"Private.account": {
28+
"type": [
29+
"boolean"
30+
]
31+
},
32+
"has_profile_picture": {
33+
"type": [
34+
"boolean"
35+
]
36+
},
37+
"rating": {
38+
"type": [
39+
"boolean"
40+
]
41+
}
42+
},
43+
"required": [
44+
"Number.of.posts",
45+
"Number.of.people.they.follow",
46+
"Number.of.followers",
47+
"has_profile_picture",
48+
"Private.account",
49+
"rating"
50+
],
51+
"type": "object"
52+
},
53+
"ui_schema": {
54+
"Number.of.followers": {},
55+
"Number.of.people.they.follow": {},
56+
"Number.of.posts": {},
57+
"Private.account": {"ui:widget": "radio"},
58+
"has_profile_picture": {"ui:widget": "radio"},
59+
"rating": {}
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import json
2+
import pandas as pd
3+
import cloudpickle
4+
from sklearn.ensemble import RandomForestClassifier
5+
from mlserve import build_schema
6+
7+
8+
columns = [
9+
'Number.of.posts',
10+
'Number.of.people.they.follow',
11+
'Number.of.followers',
12+
'has_profile_picture',
13+
'Private.account']
14+
target_name = 'rating'
15+
16+
dtypes = {
17+
'Number.of.posts': 'uint32',
18+
'Number.of.people.they.follow': 'uint32',
19+
'Number.of.followers': 'uint32',
20+
'has_profile_picture': 'bool',
21+
'Private.account': 'bool',
22+
}
23+
24+
data = pd.read_csv('labelled_1000_inclprivate.csv', dtype=dtypes)
25+
26+
X_train = data[columns]
27+
y_train = data[target_name]
28+
original = pd.concat([X_train, y_train], axis=1)
29+
30+
rfc = RandomForestClassifier(n_estimators=100)
31+
rfc.fit(X_train, y_train)
32+
print(rfc.predict_proba(X_train))
33+
34+
35+
print('Writing model')
36+
with open('instgram_rf.pkl', 'wb') as f:
37+
cloudpickle.dump(rfc, f)
38+
39+
40+
print('Writing dataset schema')
41+
schema = build_schema(original)
42+
with open('instagram.json', 'w') as f:
43+
json.dump(schema, f, indent=4, sort_keys=True)
929 KB
Binary file not shown.

0 commit comments

Comments
 (0)