Skip to content

HW 18#3

Open
alibibio wants to merge 1 commit into
mainfrom
HW_18
Open

HW 18#3
alibibio wants to merge 1 commit into
mainfrom
HW_18

Conversation

@alibibio

Copy link
Copy Markdown
Owner

No description provided.

@alibibio alibibio self-assigned this May 15, 2024

@nvaulin nvaulin left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Привет!

Хорошая работа. Не совсем понял зачем ты добавила картинки из описания дз в репозиторий. а еще я не нашел тесты.

Баллы: 25/25 (RF) + 0/10 (Тесты) + 9/15 (Репозиторий и качество кода; не вижу примеров в ноутбуке помимо RF) = 34*0.5 (сдано после дедлайна) = 17

Comment thread custom_random_forest.py
Comment on lines +29 to +42
def fit_one_tree(self, args):
X, y, i = args
n_features = X.shape[1]

np.random.seed(self.random_state + i)
if self.max_features is None:
self.max_features = n_features
feat_ids = np.random.choice(n_features, self.max_features, replace=False)
bootstrap_indices = np.random.choice(np.arange(X.shape[0]), size=X.shape[0], replace=True)
X_bootstrap = X[bootstrap_indices][:, feat_ids]
y_bootstrap = y[bootstrap_indices]
tree = DecisionTreeClassifier(max_depth=self.max_depth, random_state=self.random_state)
tree.fit(X_bootstrap, y_bootstrap)
return tree, feat_ids

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Супер. Только я бы еще по смыслу добавил _ в названии метода чтобы подчеркнуть что это не часть публичного интерфейса, а еще переменная i не очень хорошее имя. Это же не просто счетчик. Можно, нарпимер, tree_id.

Suggested change
def fit_one_tree(self, args):
X, y, i = args
n_features = X.shape[1]
np.random.seed(self.random_state + i)
if self.max_features is None:
self.max_features = n_features
feat_ids = np.random.choice(n_features, self.max_features, replace=False)
bootstrap_indices = np.random.choice(np.arange(X.shape[0]), size=X.shape[0], replace=True)
X_bootstrap = X[bootstrap_indices][:, feat_ids]
y_bootstrap = y[bootstrap_indices]
tree = DecisionTreeClassifier(max_depth=self.max_depth, random_state=self.random_state)
tree.fit(X_bootstrap, y_bootstrap)
return tree, feat_ids
def _fit_one_tree(self, args):
X, y, tree_id = args
n_features = X.shape[1]
np.random.seed(self.random_state + tree_id)
if self.max_features is None:
self.max_features = n_features
feat_ids = np.random.choice(n_features, self.max_features, replace=False)
bootstrap_indices = np.random.choice(np.arange(X.shape[0]), size=X.shape[0], replace=True)
X_bootstrap = X[bootstrap_indices][:, feat_ids]
y_bootstrap = y[bootstrap_indices]
tree = DecisionTreeClassifier(max_depth=self.max_depth, random_state=self.random_state)
tree.fit(X_bootstrap, y_bootstrap)
return tree, feat_ids

Comment thread imgs/WhCh.png

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔🤔

Comment thread requirements.txt
@@ -0,0 +1,374 @@
aiobotocore @ file:///croot/aiobotocore_1682536655331/work

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants