251 - 301 Flashcards

1
Q

pandas.DataFrame.plot(*args, **kwargs)

A

method to create diagrams.

The kind of plot to produce:
- ‘line’ : line plot (default)
- ‘bar’ : vertical bar plot
- ‘barh’ : horizontal bar plot
- ‘hist’ : histogram
- ‘box’ : boxplot
- ‘kde’ : Kernel Density Estimation plot
- ‘density’ : same as ‘kde’
- ‘area’ : area plot
- ‘pie’ : pie plot
- ‘scatter’ : scatter plot (DataFrame only)
- ‘hexbin’ : hexbin plot (DataFrame only)

df.plot()
df_pop_ceb.plot(kind="scatter", x="Year", y="Total Urban Population")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Underfitting

A

Underfitting is the inverse of overfitting, meaning that the statistical model or machine learning algorithm is too simplistic to accurately represent the data. A sign of underfitting is when there is a high bias and low variance detected in the current model or algorithm used (the inverse of overfitting: low bias and high variance).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Overfitting

A

явление, когда построенная модель хорошо объясняет примеры из обучающей выборки, но относительно плохо работает на примерах, не участвовавших в обучении (на примерах из тестовой выборки). Иными словами, модель запоминает огромное количество всех возможных примеров вместо того, чтобы научиться подмечать особенности.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

string.punctuation

A

will give all sets of punctuation.

import string 
result = string.punctuation 
print(result)

👉 !"#$%&'()*+, -./:;<=>?@[\]^_`{|}~
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

nltk.tokenize.word_tokenize()

A

divide strings into lists of substrings. For example, tokenizers can be used to find the words and punctuation in a string.

from nltk.tokenize import word_tokenize
s = ‘'’Good muffins cost $3.88\nin New York. Please buy me two of them.\n\nThanks.’’’

word_tokenize(s)

👉 [‘Good’, ‘muffins’, ‘cost’, ‘$’, ‘3.88’, ‘in’, ‘New’, ‘York’, ‘.’, ‘Please’, ‘buy’, ‘me’, ‘two’, ‘of’, ‘them’, ‘.’, ‘Thanks’, ‘.’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

nltk.stem.WordNetLemmatizer()

A

process of grouping together the different inflected forms of a word so they can be analyzed as a single item. Lemmatization is similar to stemming but it brings context to the words.

from nltk.stem import WordNetLemmatizer
lemmatizer = WordNetLemmatizer()
👉 print("rocks :", lemmatizer.lemmatize("rocks"))
print("corpora :", lemmatizer.lemmatize("corpora"))
👉 corpora : corpus
print("better :", lemmatizer.lemmatize("better", pos ="a"))
👉 better : good
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

nltk.corpus.stopwords()

A

commonly used words (such as “the”, “a”, “an”, “in”) that a search engine has been programmed to ignore

import nltk
from nltk.corpus import stopwords
print(stopwords.words('English'))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

pmdarima.arima.ndiffs(x, alpha=0.05, test=’kpss’, max_d=2, **kwargs)

A

Estimate ARIMA differencing term, d. Perform a test of stationarity for different levels of d to estimate the number of differences required to make a given time series stationary.

from pmdarima.arima.utils import ndiffs
ndiffs(df['linearized'])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

sklearn.naive_bayes.MultinomialNB(*, alpha=1.0, fit_prior=True, class_prior=None)

A

Классификатор Naive Bayes для мультиномиальных моделей. Мультиномиальный классификатор Naive Bayes подходит для классификации с дискретными характеристиками (например, подсчет слов для классификации текста).

from sklearn.naive_bayes import MultinomialNB

rng = np.random.RandomState(1)
X = rng.randint(5, size=(6, 100))
y = np.array([1, 2, 3, 4, 5, 6])

clf = MultinomialNB()
clf.fit(X, y)
print(clf.predict(X[2:3]))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

sklearn.decomposition.LatentDirichletAllocation(n_components=10, *, doc_topic_prior=None, topic_word_prior=None, learning_method=’batch’, learning_decay=0.7, learning_offset=10.0, max_iter=10, batch_size=128, evaluate_every=-1, total_samples=1000000.0, perp_tol=0.1,
mean_change_tol=0.001, max_doc_update_iter=100, n_jobs=None, verbose=0, random_state=None)

A

Скрытое распределение Дирихлета с онлайн вариационным алгоритмом Байеса.

X, _ = make_multilabel_classification(random_state=0)
lda = LatentDirichletAllocation(n_components=5, random_state=0)
lda.fit(X)
lda.transform(X[-2:])

👉 array([[0.00360392, 0.25499205, 0.0036211 , 0.64236448, 0.09541846], [0.15297572, 0.00362644, 0.44412786, 0.39568399, 0.003586 ]])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

mlxtend.plotting.plot_decision_regions(X, y, clf=svm, legend=2)

A

Visualize the decision regions of a classifier. A function for plotting decision regions of classifiers in 1 or 2 dimensions.

from mlxtend.plotting import plot_decision_regions

iris = datasets.load_iris()
X = iris.data[:, [0, 2]]
y = iris.target

svm = SVC(C=0.5, kernel='linear')
svm.fit(X, y)

Plotting decision regions
plot_decision_regions(X, y, clf=svm, legend=2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

tf.keras.utils.to_categorical(y, num_classes=None, dtype=’float32’)

A

Converts a class vector (integers) to a binary class on numpy arrays.

a = tf.keras.utils.to_categorical([0, 1, 2, 3], num_classes=4)
a = tf.constant(a, shape=[4, 4])
print(a)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

tf.keras.activations

A

Built-in activation functions:

  • relu() - Applies the rectified linear unit activation function.
  • tanh() - Hyperbolic tangent activation function.
  • sigmoid() - For CLASSIFICATION TASKS. (CLASSIFICATION WITH 2 CLASSES)
  • softmax() - For CLASSIFICATION TASKS. Converts numbers into probabilities that sum to 1. (CLASSIFICATION WITH 14 CLASSES)
  • linear() - For REGRESSION TASKS. (REGRESSION WITH 1 or 16 OUTPUTS)
  • deserialize() - Returns activation function given a string identifier.
  • elu() - Exponential Linear Unit.
  • exponential() - Exponential activation function.
  • gelu() - Applies the Gaussian error linear unit (GELU) activation function.
  • get() - Returns function.
  • hard_sigmoid() - Hard sigmoid activation function.
  • selu() - Scaled Exponential Linear Unit (SELU).
  • serialize() - Returns the string identifier of an activation function.
  • softplus() - Softplus activation function, softplus(x) = log(exp(x) + 1).
  • softsign() - Softsign activation function, softsign(x) = x / (abs(x) + 1).
  • swish() - Swish activation function, swish(x) = x * sigmoid(x).
👉 Regression of size 1
model = Sequential()
model.add(layers.Dense(10, activation='relu', input_dim=100))

model.add(...)
model.add(layers.Dense(1, activation='linear'))
👉 Classification with 8 classes
model = Sequential()
model.add(layers.Dense(10, activation='relu', input_dim=100))
model.add(...)
model.add(layers.Dense(8, activation='softmax'))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

tf.keras.metrics.AUC(num_thresholds=200, curve=’ROC’, summation_method=’interpolation’, name=None, dtype=None, thresholds=None, multi_label=False, num_labels=None, label_weights=None,
from_logits=False)

A

Approximates the AUC (Area under the curve) of the ROC or PR curves.

m = tf.keras.metrics.AUC(num_thresholds=3)
m.update_state([0, 0, 1, 1], [0, 0.5, 0.3, 0.9])

tp = [2, 1, 0], fp = [2, 0, 0], fn = [0, 1, 2], tn = [0, 2, 2]
tp_rate = recall = [1, 0.5, 0], fp_rate = [1, 0, 0]
auc = ((((1+0.5)/2)*(1-0)) + (((0.5+0)/2)*(0-0))) = 0.75
m.result().numpy()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

tf.math.square(x, name=None)

A

Computes square of x element-wise.

tf.math.square([-2., 0., 3.])
👉 [4., 0., 9.]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

tf.math.reduce_mean(input_tensor, axis=None, keepdims=False, name=None)

A

Computes the mean of elements across dimensions of a tensor.

x = tf.constant([[1., 1.], [2., 2.]])
tf.reduce_mean(x)
👉 [1.5]

tf.reduce_mean(x, 0)
👉 [1.5, 1.5]

tf.reduce_mean(x, 1)
👉 [1., 2.]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

sklearn.preprocessing.Normalizer(norm=’l2’, *, copy=True)

A

Нормализуйте образцы по отдельности в соответствии с единичной нормой. Каждая выборка (т.е. каждая строка матрицы данных)с хотя бы одной ненулевой компонентой масштабируется независимо от других выборок так, чтобы ее норма (l1,l2 или inf) равнялась единице.

from sklearn.preprocessing import Normalizer
X = [[4, 1, 2, 2], [1, 3, 9, 3], [5, 7, 5, 1]]
transformer = Normalizer().fit(X) 

transformer.transform(X)
👉 array([[0.8, 0.2, 0.4, 0.4], [0.1, 0.3, 0.9, 0.3], [0.5, 0.7, 0.5, 0.1]])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

tf.keras.layers.Normalization(axis=-1, mean=None, variance=None, **kwargs)

A

Этот слой будет приводить свои входные данные к распределению, центрированному вокруг 0 со стандартным отклонением 1.

adapt_data = np.array([[1.], [2.], [3.], [4.], [5.]], dtype=np.float32)
input_data = np.array([[1.], [2.], [3.]], np.float32)
layer = Normalization()
layer.adapt(adapt_data)
layer(input_data)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

tf.keras.regularizers

A
class L1: A regularizer that applies an L1 regularization penalty.
class L1L2: A regularizer that applies both L1 and L2 regularization penalties.
class L2: A regularizer that applies an L2 regularization penalty.
class OrthogonalRegularizer: A regularizer that encourages input vectors to be orthogonal to each other.
class Regularizer: Regularizer base class.
dense = tf.keras.layers.Dense(3, kernel_regularizer='l1_l2')
class L2Regularizer(tf.keras.regularizers.Regularizer)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Бинаризация

A

Это обычная операция по подсчету текстовых данных, при которой аналитик может решить рассмотреть только наличие или отсутствие признака, а не, например, количественное число происшествий.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

sklearn.preprocessing.Binarizer(*, threshold=0.0, copy=True)

A

Бинаризация данных (установка значений признаков в 0 или 1) в соответствии с порогом.

from sklearn.preprocessing import Binarizer
X = [[ 1., -1.,  2.], [ 2.,  0.,  0.], [ 0.,  1., -1.]]
transformer = Binarizer().fit(X)
transformer.transform(X)
👉 array([[1., 0., 1.], [1., 0., 0.], [0., 1., 0.]])
22
Q

matplotlib.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, *, edgecolors=None, plotnonfinite=False, data=None, **kwargs)

A

Function to draw a scatter plot. The scatter() function plots one dot for each observation. It needs two arrays of the same length, one for the values of the x-axis, and one for values on the y-axis.

plt.scatter(x=X[:, 0], y=X[:, 1], c=y);
plt.scatter(X.T[0], X.T[1], c=y)
x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
plt.scatter(x, y)
plt.show()
23
Q

numpy.log(x, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, subok=True[, signature, extobj])

A

A mathematical function that helps the user to calculate the Natural logarithm of x where x belongs to all the input array elements.

in_array = [1, 3, 5, 2**8]
out_array = np.log(in_array)
👉 Output array :  [ 0.          1.09861229  1.60943791  5.54517744]
in_array = [1, 1.2, 1.4, 1.6, 1.8, 2]
out_array = np.log(in_array)
👉 out_array :  [ 0.          0.18232156  0.33647224  0.47000363  0.58778666 
0.69314718]
24
Q

tf.keras.optimizers.schedules.ExponentialDecay(initial_learning_rate, decay_steps, decay_rate, staircase=False, name=None)

A

A LearningRateSchedule that uses an exponential decay schedule.

initial_learning_rate = 0.1

lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(initial_learning_rate, decay_steps=100000, decay_rate=0.96, staircase=True)

model. compile(optimizer=tf.keras.optimizers.SGD(learning_rate=lr_schedule), loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model. fit(data, labels, epochs=5)
25
Q

tf.keras.optimizers.Adam(learning_rate=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-07, amsgrad=False, name=’Adam’, **kwargs)

A

Adam optimization is a stochastic gradient descent method that is based on adaptive estimation of first-order and second-order moments.

adam_opt = optimizers.Adam(learning_rate=0.01, beta_1=0.9, beta_2=0.999)
opt = tf.keras.optimizers.Adam(learning_rate=0.1)
var1 = tf.Variable(10.0)
loss = lambda: (var1 ** 2)/2.0 # d(loss)/d(var1) == var1
step_count = opt.minimize(loss, [var1]).numpy()
var1.numpy()
👉 9.9
26
Q

tf.keras.backend.expand_dims(x, axis=-1)

A

Увеличить размерность на единиц.

image = tf.zeros([10,10,3])
tf.expand_dims(image, axis=0).shape.as_list()
👉 [1, 10, 10, 3]
one_img = tf.expand_dims(one_img, 0)
one_img = tf.expand_dims (one_img, -1) 
👉 -1 означает последнее измерение
27
Q

tf.keras.callbacks.EarlyStopping(monitor=’val_loss’, min_delta=0, patience=0, verbose=0, mode=’auto’, baseline=None, restore_best_weights=False)

A

Останавливает модель если через определенное количество иттераций не было улучшений.

from tensorflow.keras.callbacks import EarlyStopping
es = EarlyStopping(patience = 30, restore_best_weights = True)

history = model.fit(X_train, y_train, validation_split = 0.3, epochs = 500, batch_size = 16, verbose = 0, callbacks = [es])
es = callbacks.EarlyStopping(patience=30, restore_best_weights=True)
model.fit(X, y, batch_size=16, epochs=100, validation_split=0.3, callbacks=[es], verbose=0)
28
Q

tf.keras.Sequential()

A

STEP 2: OPTIMIZATION METHODS

Группирует линейный стек слоев. When you want to create a model that does not have multiple inputs and outputs, it will be developed layer by layer.

model = Sequential()
model.add(layers.Dense(100, input_dim=128, activation='relu'))  # specify input size
model.add(layers.Dense(10, activation='relu'))
model.add(layers.Dense(10, activation='relu'))
model.add(layers.Dense(5, activation='softmax')) #Must correspond to the task 
model.compile(loss='categorical_crossentropy', optimizer='adam')
# SETP 3: DATA AND FITTING METHODS
es = callbacks.EarlyStopping(patience=30, restore_best_weights=True)
model.fit(X, y, batch_size=16, epochs=100, validation_split=0.3, callbacks=[es], verbose=0)
### REGRESSION WITH 1 OUTPUT
model.add(layers.Dense(1, activation='linear'))
### REGRESSION WITH 16 OUTPUTS
model.add(layers.Dense(16, activation='linear'))
### CLASSIFICATION WITH 2 CLASSES
model.add(layers.Dense(1, activation='sigmoid'))
### CLASSIFICATION WITH 14 CLASSES
model.add(layers.Dense(14, activation='softmax')
29
Q

numpy.array_split(ary, indices_or_sections) numpy.vsplit()

A

numpy. array_split() — splitting arrays, we pass it the array we want to split and the number of splits.
numpy. vsplit() — Split an array into multiple sub-arrays vertically (row-wise).
numpy. hsplit() — Split an array into multiple sub-arrays horizontally (column-wise).
numpy. dsplit() — Split array into multiple sub-arrays along the 3rd axis (depth).

arr = np.array([1, 2, 3, 4, 5, 6])
newarr = np.array_split(arr, 4)

👉 [array([1, 2]), array([3, 4]), array([5]), array([6])]
arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]])
newarr = np.array_split(arr, 3, axis=1)

👉 [array([[ 1],[ 4],[ 7],[10],[13],[16]]), array([[ 2],[ 5],[ 8],[11],[14],[17]]), array([[ 3],[ 6],[ 9],[12],[15],[18]])]
x = np.array([0, 1, 2, 3, 4, 5])
np.hsplit(x, 2)

👉 [array([0, 1, 2]), array([3, 4, 5])]
30
Q

math.isclose(a, b, rel_tol, abs_tol)

A

Method checks whether two values are close to each other, or not. Returns True if the values are close, otherwise False.

This method uses a relative or absolute tolerance, to see if the values are close. formula : abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)

print(math.isclose(1.233, 1.4566))
👉 False
print(math.isclose(1.233, 1.233))
👉 True
print(math.isclose(1.233, 1.24))
👉 False
print(math.isclose(1.233, 1.233000001))
👉 True
#compare the closeness of two values
print(math.isclose(8.005, 8.450, abs_tol = 0.4))
👉 False
31
Q

git stash

A

Temporarily shelves (в полку) changes you’ve made to your working copy so you can work on something else, and then come back and re-apply them later on.

💡 Saving staged and unstaged changes to stash for later use (see below for the explanation of a stash)
git stash
💡 Stashing staged, unstaged and untracked files as well
git stash -u
💡 Stashing everything (including ignored files)
git stash --all
💡 Reapply previously stashed changes and empty the stash
git stash pop
💡 Reapply previously stashed changes and keep the stash
git stash apply
💡 Dropping changes in the stash
git stash drop
32
Q

numpy.save(file, arr, allow_pickle=True, fix_imports=True)

A

Save an array to a binary file in NumPy .npy format.

from tempfile import TemporaryFile

outfile = TemporaryFile()
x = np.arange(10)
np.save(outfile, x)from tempfile import TemporaryFile
outfile = TemporaryFile()

x = np.arange(10)
np.save(outfile, x)
33
Q

numpy.maximum(x1, x2, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, subok=True[, signature, extobj])

A

Element-wise maximum of array elements. Compare two arrays and returns a new array containing the element-wise maxima.

np.maximum([2, 3, 4], [1, 5, 2])
👉 array([2, 5, 4])
34
Q

numpy.load(file, mmap_mode=None, allow_pickle=False, fix_imports=True, encoding=’ASCII’)

A

Load arrays or pickled objects from .npy, .npz or pickled files.

np. save('/tmp/123', np.array([[1, 2, 3], [4, 5, 6]]))
np. load('/tmp/123.npy')

👉 array([[1, 2, 3], [4, 5, 6]])
35
Q

numpy.multiply(x1, x2, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, subok=True[, signature, extobj])

A

Multiply arguments element-wise.

np. multiply(2.0, 4.0)
👉 8. 0
x1 = np.arange(9.0).reshape((3, 3))
x2 = np.arange(3.0)
np.multiply(x1, x2)
👉 array([[  0.,   1.,   4.], [  0.,   4.,  10.],  [  0.,   7.,  16.]])
36
Q

tf.keras.Input(shape=None, batch_size=None, name=None, dtype=None, sparse=None, tensor=None, ragged=None, type_spec=None, **kwargs)

A

Input() используется для создания тензора Кераса. Тензор Keras дополняем определенными атрибутами, что позволяет нам построить модель Keras, просто зная входы и выходы модели.

from tensorflow import keras

input = keras.Input(shape=(32, 32, 3))
x = Conv2D(32, 3, activation='relu')
x = x(input)
x = Conv2D(32, 3, activation='relu')(input)
input = keras.Input(shape=(32, 32, 3))
x = layers.Conv2D(32, 3, activation='relu')(input)
x = layers.MaxPooling2D(2, padding='same')(x)
x = layers.Conv2D(64, 3, activation='relu')(x)
x = layers.MaxPooling2D(2, padding='same')(x)
x = layers.Flatten()(x)
x = layers.Dense(256, activation='relu')(x)
x = layers.Dropout(0.5)(x)
output = layers.Dense(10, activation='softmax')(x)
model = keras.Model(inputs=input, outputs=output)
37
Q

tensor

A

an array of dimension 3 or more.

38
Q

matrix

A

an array of dimension 2.

39
Q

tf.keras.layers.Reshape(target_shape, **kwargs)

A

Слой, который перестраивает входные данные в заданную форму.

model = tf.keras.Sequential()
model.add(tf.keras.layers.Reshape((3, 4), input_shape=(12,)))

model.output_shape
👉 (None, 3, 4)

model.add(tf.keras.layers.Reshape((6, 2)))
model.output_shape
👉 (None, 6, 2)
40
Q

tf.keras.metrics.categorical_crossentropy(y_true, y_pred, from_logits=False, label_smoothing=0.0, axis=-1)

A

Вычисляет категорическую потерю кроссэнтропии. Позволяющая оценить, насколько хорошо функционирует модель классификации в машинном обучении(между 0 и 1, где 0 – идеальная модель).

👉 Использовать для 👉 Classification with more classes 3+++

y_true = [[0, 1, 0], [0, 0, 1]]
y_pred = [[0.05, 0.95, 0], [0.1, 0.8, 0.1]]
loss = tf.keras.losses.categorical_crossentropy(y_true, y_pred)
assert loss.shape == (2,)

loss.numpy()
👉 array([0.0513, 2.303], dtype=float32)

model.compile(loss='categorical_crossentropy')
41
Q

vector

A

An array of dimension 1.

42
Q

tf.keras.losses.BinaryCrossentropy(from_logits=False, label_smoothing=0.0, axis=-1, reduction=losses_utils.ReductionV2.AUTO, name=’binary_crossentropy’)

A

Computes the cross-entropy loss between true labels and predicted labels. Вычисляет потери бинарной кроссэнтропии.

👉 Использовать для 👉 Classification with 2 classes

y_true = [0, 1, 0, 0]
y_pred = [-18.6, 0.51, 2.94, -12.8]
bce = tf.keras.losses.BinaryCrossentropy(from_logits=True)
bce(y_true, y_pred).numpy()

👉 0.865

model.compile(loss='binary_crossentropy')
43
Q

pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=None)

A

Two-dimensional, size-mutable, potentially heterogeneous tabular data.

d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d, dtype=np.int8)
d = {'col1': [0, 1, 2, 3], 'col2': pd.Series([2, 3], index=[2, 3])}
pd.DataFrame(data=d, index=[0, 1, 2, 3])
df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),  columns=['a', 'b', 'c'])
44
Q

tqdm.tqdm()

A

Предназначен для быстрого и расширяемого внедрения индикаторов выполнения (progressbar) во внешние интерфейсы программ на Python, предоставляя конечным пользователям визуальную индикацию хода вычислений или передачи данных. Основное и оригинальное использование tqdm это оборачивание итерируемых объектов Python.

list1 = ["My","Name","Is","Ashwini","Mandani"]
list1 = [(sleep(2), print(i)) for i in tqdm(list1)]
list1 = ["My","Name","Is","Ashwini","Mandani"]
list1 = [(sleep(2), print(i)) for i in tqdm_gui(list1)]
45
Q

tf.keras.Model(*args, **kwargs)

A

Groups layers into an object with training and inference features. Запихнуть в модель данные ввиде инпута и аутпута.

inputs = tf.keras.layers.Input(shape=(3,))
outputs = tf.keras.layers.Dense(2)(inputs)

model = tf.keras.models.Model(inputs=inputs, outputs=outputs)
model.compile(optimizer="Adam", loss="mse", metrics=["mae"])

x = np.random.random((2, 3))
y = np.random.randint(0, 2, (2, 2))
model.fit(x, y)
46
Q

tf.keras.layers.Dropout(rate, noise_shape=None, seed=None, **kwargs)

A

Слой Выпадения случайным образом устанавливает входные блоки в 0 с частотой rate на каждый шаг во время тренировки, которая помогает предотвратить переобучения. Входы, для которых не установлено значение 0, масштабируются на 1 / (1 - коэффициент), так что сумма по всем входам не изменяется.

Обратите внимание, что слой Dropout применяется только в том случае, если для training установлено значение True, так что никакие значения не удаляются во время вывода.

tf.random.set_seed(0)
layer = tf.keras.layers.Dropout(.2, input_shape=(2,))
data = np.arange(10).reshape(5, 2).astype(np.float32)

print(data)
👉 [[0. 1.]  [2. 3.] [4. 5.] [6. 7.] [8. 9.]] outputs = layer(data, training=True)

👉 tf.Tensor([[ 0.    1.25] [ 2.5   3.75] [ 5.    6.25] [ 7.5   8.75] [10.    0.  ]], shape=(5, 2), dtype=float32)
47
Q

tf.keras.utils.image_dataset_from_directory(directory, labels=’inferred’, label_mode=’int’, class_names=None, color_mode=’rgb’, batch_size=32, image_size=(256, 256), shuffle=True, seed=None, validation_split=None, subset=None, interpolation=’bilinear’, follow_links=False, crop_to_aspect_ratio=False, **kwargs)

A

Generates a tf.data.Dataset from image files in a directory. Забрать все изображения с выбранной папки.

48
Q

tf.keras.preprocessing.image.ImageDataGenerator(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, zca_epsilon=1e-06, rotation_range=0, width_shift_range=0.0, height_shift_range=0.0, brightness_range=None, shear_range=0.0, zoom_range=0.0, channel_shift_range=0.0, fill_mode=’nearest’, cval=0.0, horizontal_flip=False, vertical_flip=False, rescale=None, preprocessing_function=None, data_format=None, validation_split=0.0, interpolation_order=1, dtype=None)

A

Генерация пакетов данных тензорного изображения с дополнением данных в реальном времени.

train_datagen = ImageDataGenerator(rescale=1./255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale=1./255)

train_generator = train_datagen.flow_from_directory('data/train', target_size=(150, 150), batch_size=32, class_mode='binary')
validation_generator = test_datagen.flow_from_directory('data/validation', target_size=(150, 150), batch_size=32, class_mode='binary')
model.fit(train_generator, steps_per_epoch=2000, epochs=50, validation_data=validation_generator, validation_steps=800)
49
Q

tf.keras.layers.AveragePooling2D(pool_size=(2, 2), strides=None, padding=’valid’, data_format=None, **kwargs)

A

Средняя операция объединения пространственных данных.

x = tf.constant([[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]])
x = tf.reshape(x, [1, 3, 3, 1])
avg_pool_2d = tf.keras.layers.AveragePooling2D(pool_size=(2, 2), strides=(1, 1), padding='valid')

avg_pool_2d(x)
👉 array([[[[3.], [4.]], [[6.], [7.]]]])
50
Q

tf.keras.layers.Conv2D(filters, kernel_size, strides=(1, 1), padding=’valid’, data_format=None, dilation_rate=(1, 1), groups=1, activation=None, use_bias=True, kernel_initializer=’glorot_uniform’, bias_initializer=’zeros’, kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None, **kwargs) — 2D convolution layer (e.g. spatial convolution over images)

A

Этот слой создает ядро свертки, которое сворачивается со входом слоя для создания тензора выходных данных.

👉 nput_shape=(128, 128, 3) 👉 для изображений RGB 128x128

input_shape = (4, 28, 28, 3)
x = tf.random.normal(input_shape)
y = tf.keras.layers.Conv2D(2, 3, activation='relu', input_shape=input_shape[1:])(x)

print(y.shape)
👉 (4, 26, 26, 2)
# With `padding` as "same".
input_shape = (4, 28, 28, 3)
x = tf.random.normal(input_shape)
y = tf.keras.layers.Conv2D(2, 3, activation='relu', padding="same", input_shape=input_shape[1:])(x)

print(y.shape)
👉 (4, 28, 28, 2)
51
Q

tf.keras.layers.MaxPool2D(pool_size=(2, 2), strides=None, padding=’valid’, data_format=None, **kwargs)

A

Операция максимального объединения для двумерных пространственных данных. Субдискретизирует входное представление путем принятия максимальное значение по окну, определенному pool_size для каждого размера вдоль оси функций. Окно смещается на strides в каждом размере.

x = tf.constant([[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]])
x = tf.reshape(x, [1, 3, 3, 1])
max_pool_2d = tf.keras.layers.MaxPooling2D(pool_size = (2, 2), strides=(1, 1), padding='valid')

max_pool_2d(x)