Skip to content
Permalink
Browse files
Patch broken links in app homepage
  • Loading branch information
Nasser Kaze committed Aug 5, 2021
1 parent 0358658 commit 2bf33040fd6439753fbe438e62bc9a3a59462c45
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 16 deletions.
@@ -82,7 +82,7 @@ class PredictionRequest(models.Model):
prediction = models.CharField(max_length=128)
feedback = models.CharField(max_length=128, blank=True, null=True)
notes = models.TextField(blank=True, null=True)
algorithm: Algorithm = models.ForeignKey(Algorithm, on_delete=models.CASCADE)
algorithm: Algorithm = models.ForeignKey(Algorithm, on_delete=models.DO_NOTHING, blank=True)
created_at: date = models.DateTimeField(auto_now_add=True, blank=True)
created_by = models.CharField(max_length=128)

@@ -66,13 +66,20 @@ class AlgorithmViewSet(viewsets.ModelViewSet):
OpenApiParameter(name='version',
description='Algorithm version',
required=True,
default='0.0.1',
examples=[OpenApiExample('Example 1', value='0.0.1')]),
],
operation_id='algorithms_predict',
request=Dict[str, Any],
responses=inline_serializer(name="PredictionResponse",
fields={"probability": FloatField(),
"label": CharField(),
"method": CharField(),
"color": CharField(),
"wilkis_lambda": FloatField(),
"pillais_trace": FloatField(),
"hotelling_tawley": FloatField(),
"roys_reatest_roots": FloatField(),
"request_id": IntegerField()})
)
@action(detail=False, methods=['post'])
@@ -81,8 +88,10 @@ def predict(self, request, format=None):
try:
classifier = self.request.query_params.get("classifier")
region = self.request.query_params.get("dataset", "Germany")
version = self.request.query_params.get("version")
version = self.request.query_params.get("version", "0.0.1")
status = self.request.query_params.get("status", "production")

print(request)

if version is None:
raise bad_request(request=request,
@@ -91,19 +100,20 @@ def predict(self, request, format=None):
raise bad_request(request=request,
data={"error": "Missing required query parameter: classifier"})

algorithm: Algorithm = Algorithm.objects.filter(classifier=classifier,
status=status,
version=version,
dataset__name=region)[0]

if algorithm is None:
raise bad_request(request=request,
data={"error": "ML algorithm is not available"})

if classifier in ['manova', 'linearRegression', 'polynomialRegression']:
prediction = stat_score(request.data, classifier)
algorithm = None

else:
algorithm: Algorithm = Algorithm.objects.filter(classifier=classifier,
status=status,
version=version,
dataset__name=region)[0]

if algorithm is None:
raise bad_request(request=request,
data={"error": "ML algorithm is not available"})
classifier = registry.classifiers[algorithm.id]
prediction = classifier.compute_prediction(request.data)

@@ -91,7 +91,7 @@ <h3 class="title">Live Demo</h3>
</div>
<h3 class="title">Swagger Docs</h3>
<p class="intro">Explore web API documentation with swagger</p>
<a class="link" href="{{ host }}/api-docs/swagger-ui" target="_blank"><span></span></a>
<a class="link" href="/api-docs/swagger-ui" target="_blank"><span></span></a>
</div>
</div>
<div class="item item-purple col-lg-4 col-6">
@@ -101,7 +101,7 @@ <h3 class="title">Swagger Docs</h3>
</div>
<h3 class="title">Redoc</h3>
<p class="intro">Explore web API documentation with redoc</p>
<a class="link" href="{{ host }}/api-docs/redoc" target="_blank"><span></span></a>
<a class="link" href="/api-docs/redoc" target="_blank"><span></span></a>
</div>
</div>
<div class="item item-pink col-lg-4 col-6">
@@ -111,7 +111,7 @@ <h3 class="title">Redoc</h3>
</div>
<h3 class="title">Browsable API</h3>
<p class="intro">Explore django rest framework browsable API.</p>
<a class="link" href="{{ host }}/api/v1/" target="_blank"><span></span></a>
<a class="link" href="/api/v1/" target="_blank"><span></span></a>
</div>
</div>
</div>
@@ -193,6 +193,7 @@ paths:
name: version
schema:
type: string
default: 0.0.1
description: Algorithm version
required: true
examples:
@@ -499,7 +500,6 @@ components:
algorithm:
type: integer
required:
- algorithm
- created_at
- created_by
- id
@@ -514,12 +514,34 @@ components:
format: float
label:
type: string
method:
type: string
color:
type: string
wilkis_lambda:
type: number
format: float
pillais_trace:
type: number
format: float
hotelling_tawley:
type: number
format: float
roys_reatest_roots:
type: number
format: float
request_id:
type: integer
required:
- color
- hotelling_tawley
- label
- method
- pillais_trace
- probability
- request_id
- roys_reatest_roots
- wilkis_lambda
servers:
- url: http://127.0.0.1:8000
description: server on localhost
@@ -22,10 +22,15 @@ def linear_regression(input_row, data, categorical):
le = LabelEncoder()
for val in categorical:
data[val] = le.fit_transform(data[val])

data['job'] = data['job'].astype('int')

for col in data.columns:
if(col not in categorical):
if(col not in categorical):
data[col] = (data[col] - np.mean(data[col]))/np.std(data[col])

print(data)

split = 0.8
split_idx = int(len(data)*split)
data_train = data[:split_idx]
@@ -37,6 +42,8 @@ def linear_regression(input_row, data, categorical):
x_test = data_test.loc[:, data_test.columns != 10]

reg = LinearRegression().fit(x_train, y_train)

print(data)

predictions = reg.predict(x_test)
for i in range(len(predictions)):
@@ -143,9 +150,16 @@ def manova(test_row, data, categorical):
out_good = np.array(output_good['x0']['stat'])
out_bad = np.array(output_bad['x0']['stat'])

# Wilki's Lambda
WL_good = out_good[0][0]

# Pillai's Trace
PT_good = out_good[1][0]

# Hotelling-Lawley Trace
HT_good = out_good[2][0]

# Roy's Greatest Roots
RGR_good = out_good[3][0]

WL_bad = out_bad[0][0]
@@ -164,9 +178,16 @@ def manova(test_row, data, categorical):

out_test = np.array(output_test['x0']['stat'])

# Wilki's Lambda
WL_test_good = out_test[0][0]

# Pillai's Trace
PT_test_good = out_test[1][0]

# Hotelling-Lawley Trace
HT_test_good = out_test[2][0]

# Roy's Greatest Roots
RGR_test_good = out_test[3][0]

data_test_x = x_bad.append(x)
@@ -195,10 +216,29 @@ def manova(test_row, data, categorical):

def stat_score(input_row, model_type):
df = pd.read_csv(f'zoo/data/german.csv', index_col=0)
data = df.drop(columns=['Saving accounts', 'Checking account'])
data = df.drop(columns=['Saving accounts', 'Checking account', 'Risk'])

dat_dict = data.to_dict()
new_dat_dict = {}

# rename columns(Make them lowercase and snakecase)
for key, value in dat_dict.items():
newKey = key
if type(key) == str:
newKey = newKey.lower().replace(' ', '_')
# if newKey != key:
new_dat_dict[newKey] = dat_dict[key]
del dat_dict

data = pd.DataFrame.from_dict(new_dat_dict)
del new_dat_dict

cols = data.columns
num_cols = data._get_numeric_data().columns
categorical = list(set(cols) - set(num_cols))

print(categorical)
print(input_row)

try:
if(model_type == 'manova'):

0 comments on commit 2bf3304

Please sign in to comment.