Spaces:
Running
Running
Benjamin Bossan
commited on
Commit
·
675701e
1
Parent(s):
2e1d656
Users can test their own classifiers
Browse files- index.html +40 -3
index.html
CHANGED
|
@@ -2,12 +2,49 @@
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8" />
|
|
|
|
| 5 |
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
| 6 |
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
| 7 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
</body>
|
| 13 |
</html>
|
|
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8" />
|
| 5 |
+
<title>PyScript Test</title>
|
| 6 |
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
| 7 |
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
| 8 |
+
<py-env>
|
| 9 |
+
- scikit-learn
|
| 10 |
+
- tabulate
|
| 11 |
+
</py-env>
|
| 12 |
+
|
| 13 |
+
<!-- from https://stackoverflow.com/a/62032824 -->
|
| 14 |
+
<link rel="stylesheet"
|
| 15 |
+
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/default.min.css">
|
| 16 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js"
|
| 17 |
+
integrity="sha512-gU7kztaQEl7SHJyraPfZLQCNnrKdaQi5ndOyt4L4UPL/FHDd/uB9Je6KDARIqwnNNE27hnqoWLBq+Kpe4iHfeQ=="
|
| 18 |
+
crossorigin="anonymous"
|
| 19 |
+
referrerpolicy="no-referrer"></script>
|
| 20 |
+
<script>hljs.initHighlightingOnLoad();</script>
|
| 21 |
+
|
| 22 |
</head>
|
| 23 |
<body>
|
| 24 |
+
<p>Define your own sklearn classifier and evaluate it on the toy dataset. An example is shown below:</p>
|
| 25 |
+
<pre>
|
| 26 |
+
<code class="python">from sklearn.linear_model import LogisticRegression
|
| 27 |
+
clf = LogisticRegression(random_state=0)
|
| 28 |
+
evaluate(clf)</code>
|
| 29 |
+
</pre>
|
| 30 |
+
Try to achieve a test accuracy of 0.85 or better! Get some inspiration for possible classifiers <a href="https://scikit-learn.org/stable/supervised_learning.html" title="List of sklearn estimators">here</a>.
|
| 31 |
+
<br><br>
|
| 32 |
+
Enter your code below, then press Shift+Enter:
|
| 33 |
+
<py-script>
|
| 34 |
+
from statistics import mean
|
| 35 |
+
from sklearn.datasets import make_classification
|
| 36 |
+
from sklearn.model_selection import cross_validate
|
| 37 |
+
import tabulate
|
| 38 |
+
|
| 39 |
+
X, y = make_classification(n_samples=1000, n_informative=10, random_state=0)
|
| 40 |
+
|
| 41 |
+
def evaluate(clf):
|
| 42 |
+
cv_result = cross_validate(clf, X, y, scoring='accuracy', cv=5)
|
| 43 |
+
show_result = {'split': [1, 2, 3, 4, 5], 'accuracy': cv_result['test_score']}
|
| 44 |
+
print(f"Mean test accuracy: {mean(cv_result['test_score']):.3f}")
|
| 45 |
+
return tabulate.tabulate(show_result, tablefmt='html', headers='keys', floatfmt='.3')
|
| 46 |
+
</py-script>
|
| 47 |
+
|
| 48 |
+
<py-repl auto-generate="false"></py-repl>
|
| 49 |
</body>
|
| 50 |
</html>
|