-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hi, I don't know why I cannot run your code in my jupyterlab, please help #117
Comments
It is an import error. You should install somehow that scratch module. There are different ways of doing so. In this case, follow what is written in the readme in order to export python path. Otherwise you can use sys library inside python. |
Hi bro.
I will make the necessary change!
Thank's.
Em dom., 12 de fev. de 2023 17:18, Giacomo Matrone ***@***.***>
escreveu:
… It is an import error. You should install somehow that scratch module.
There are different ways of doing so. In this case, follow what is written
in the readme in order to export python path. Otherwise you can use sys
library inside python.
—
Reply to this email directly, view it on GitHub
<#117 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ARR5MF4CR75NVDSSQFL7FO3WXFAQ5ANCNFSM6AAAAAAUXLVGZY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
hi, I follow ur reply and do it in pycharm, but it gives me a new error: Process finished with exit code 1 |
hi, I follow ur reply and do it in pycharm, but it gives me a new error: Process finished with exit code 1 |
the code I cannot run is
from typing import List
from collections import Counter
def raw_majority_vote(labels: List[str]) -> str:
votes = Counter(labels)
winner, _ = votes.most_common(1)[0]
return winner
assert raw_majority_vote(['a', 'b', 'c', 'b']) == 'b'
def majority_vote(labels: List[str]) -> str:
"""Assumes that labels are ordered from nearest to farthest."""
vote_counts = Counter(labels)
winner, winner_count = vote_counts.most_common(1)[0]
num_winners = len([count
for count in vote_counts.values()
if count == winner_count])
Tie, so look at first 4, then 'b'
assert majority_vote(['a', 'b', 'c', 'b', 'a']) == 'b'
from typing import NamedTuple
from scratch.linear_algebra import Vector, distance
class LabeledPoint(NamedTuple):
point: Vector
label: str
def knn_classify(k: int,
labeled_points: List[LabeledPoint],
new_point: Vector) -> str:
import random
def random_point(dim: int) -> Vector:
return [random.random() for _ in range(dim)]
def random_distances(dim: int, num_pairs: int) -> List[float]:
return [distance(random_point(dim), random_point(dim))
for _ in range(num_pairs)]
def main():
from typing import Dict
import csv
from collections import defaultdict
if name == "main": main()
and it give me error
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_23996\3035052844.py in
26
27 from typing import NamedTuple
---> 28 from scratch.linear_algebra import Vector, distance
29
30 class LabeledPoint(NamedTuple):
ModuleNotFoundError: No module named 'scratch.linear_algebra'
The text was updated successfully, but these errors were encountered: