您可以忽略 mypy 对单行的检查,如此处的回答。有没有办法忽略 mypy 以获得完整功能?
我正在学习神经网络,我在Keras中为UCI机器学习库中的虹膜数据集分类构建了一个简单的网络.我使用了一个带有8个隐藏节点的隐藏层网络.使用Adam优化器的学习率为0.0005,并且运行200个时期.Softmax用于输出,损失为catogorical-crossentropy.我得到以下学习曲线.
正如您所看到的,准确性的学习曲线有很多平坦的区域,我不明白为什么.错误似乎在不断减少,但准确性似乎并没有以同样的方式增加.精确度学习曲线中的平坦区域意味着什么?为什么即使错误似乎在减少,这些区域的准确度也不会增加?
这在培训中是正常的还是我更有可能在这里做错了什么?
dataframe = pd.read_csv("iris.csv", header=None)
dataset = dataframe.values
X = dataset[:,0:4].astype(float)
y = dataset[:,4]
scalar = StandardScaler()
X = scalar.fit_transform(X)
label_encoder = LabelEncoder()
y = label_encoder.fit_transform(y)
encoder = OneHotEncoder()
y = encoder.fit_transform(y.reshape(-1,1)).toarray()
# create model
model = Sequential()
model.add(Dense(8, input_dim=4, activation='relu'))
model.add(Dense(3, activation='softmax'))
# Compile model
adam = optimizers.Adam(lr=0.0005, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
model.compile(loss='categorical_crossentropy',
optimizer=adam,
metrics=['accuracy'])
# Fit the model
log = model.fit(X, y, epochs=200, batch_size=5, validation_split=0.2)
fig = plt.figure()
fig.suptitle("Adam, lr=0.0006, one hidden layer")
ax = fig.add_subplot(1,2,1) …Run Code Online (Sandbox Code Playgroud) 我正在使用不同的交叉验证方法。我首先在我的代码上使用 k Fold 方法,效果非常好,但是当我使用repeatedstratifiedkfold方法时,它给了我这个错误
TypeError: Singleton array array(None, dtype=object) cannot be considered a valid collection.
Run Code Online (Sandbox Code Playgroud)
任何人都可以在这方面帮助我吗?以下是产生该问题的最少代码。
import numpy as np
from sklearn.model_selection import RepeatedStratifiedKFold
ss = RepeatedStratifiedKFold(n_splits=5, n_repeats=2, random_state=0)
X = np.random.rand(100, 5)
y = np.random.rand(100, 1)
for train_index, test_index in ss.split(X):
X_train, X_test = X[train_index], X[test_index]
y_train, y_test = y[train_index], y[test_index]
Run Code Online (Sandbox Code Playgroud)
这是完整的引用 -
start
Traceback (most recent call last):
File "C:\Users\full details of final year project\AZU\test_tace_updated.py", line 81, in <module>
main()
File "C:\Users\AZU\test_tace_updated.py", line 54, in main …Run Code Online (Sandbox Code Playgroud) 我正在尝试从我的 Ubuntu 16.04 LTS 机器上卸载 Ananconda 并尝试关注这篇文章。
我运行了以下命令
conda install anaconda-clean
anaconda-clean
rm -rf ~/anaconda
Run Code Online (Sandbox Code Playgroud)
一切都在没有任何错误/警告的情况下被执行。事实上,当我运行时,anaconda-clean它说某某软件包已被卸载。但是,我仍然可以打开 anaconda 导航器,一切似乎都运行良好。我错过了什么?
在下面的代码中,我有两个单独的动画,并将它们绘制在两个单独的子图中。我希望它们都在一个图中运行,而不是在这个图中运行。我已经尝试过下面解释的方法,但它给我带来了如下所述的问题。请帮忙
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time as t
x = np.linspace(0,5,100)
fig = plt.figure()
p1 = fig.add_subplot(2,1,1)
p2 = fig.add_subplot(2,1,2)
def gen1():
i = 0.5
while(True):
yield i
i += 0.1
def gen2():
j = 0
while(True):
yield j
j += 1
def run1(c):
p1.clear()
p1.set_xlim([0,15])
p1.set_ylim([0,100])
y = c*x
p1.plot(x,y,'b')
def run2(c):
p2.clear()
p2.set_xlim([0,15])
p2.set_ylim([0,100])
y = c*x
p2.plot(x,y,'r')
ani1 = animation.FuncAnimation(fig,run1,gen1,interval=1)
ani2 = animation.FuncAnimation(fig,run2,gen2,interval=1)
fig.show()
Run Code Online (Sandbox Code Playgroud)
我尝试创建单个子图而不是 和p1, …
我有一个pandas数据框并且有一个列age.我想将其编码为由特定范围分隔的分类值,例如,15岁以下的年龄应为0,15到30之间应更改为1,依此类推.
我找到了这样做的方法(在经历了关于使用&和的巨大混乱之后and)
age = X.loc[:, 'Age']
age[ age<15 ] = 0
age[ (15<age) & (age<=30) ] = 1
age[ (30<age) & (age<=50) ] = 2
age[ (50<age) & (age<=80) ] = 3
Run Code Online (Sandbox Code Playgroud)
这是最好的方式吗?我可以这样做,例如使用LabelEncoder吗?
我在tensorflow中编写了以下二进制分类程序,它是错误的.无论输入是什么,成本都会一直返回到零.我正在尝试调试一个没有从数据中学到任何东西的大型程序.我已经将至少一个bug缩小到成本函数,总是返回零.给定的程序使用一些随机输入并且具有相同的问题.self.X_train并且self.y_train最初应该从文件中读取并且该函数self.predict()具有形成前馈神经网络的更多层.
import numpy as np
import tensorflow as tf
class annClassifier():
def __init__(self):
with tf.variable_scope("Input"):
self.X = tf.placeholder(tf.float32, shape=(100, 11))
with tf.variable_scope("Output"):
self.y = tf.placeholder(tf.float32, shape=(100, 1))
self.X_train = np.random.rand(100, 11)
self.y_train = np.random.randint(0,2, size=(100, 1))
def predict(self):
with tf.variable_scope('OutputLayer'):
weights = tf.get_variable(name='weights',
shape=[11, 1],
initializer=tf.contrib.layers.xavier_initializer())
bases = tf.get_variable(name='bases',
shape=[1],
initializer=tf.zeros_initializer())
final_output = tf.matmul(self.X, weights) + bases
return final_output
def train(self):
prediction = self.predict()
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=prediction, labels=self.y))
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(cost, …Run Code Online (Sandbox Code Playgroud) python artificial-intelligence machine-learning neural-network tensorflow
我正在关注本教程:https://www.pyimagesearch.com/2014/07/21/detecting-circles-images-using-opencv-hough-circles/
我正在摆弄 HoughCircles 的参数(即使是那些你在代码中没有看到的参数,例如:param2),它看起来非常不准确,在我的项目中,你在图片上看到的磁盘将被放置在随机点上,我需要能够检测它们及其颜色。
目前我只能检测到几个圆圈,有时会在没有圆圈的地方绘制一些随机圆圈,所以我有点困惑。
这是使用 openCV 进行圆检测的最佳方法还是有更准确的方法?另外为什么我的代码没有检测到每个圆圈?
初始板: https: //i.stack.imgur.com/Ba6H9.jpg
绘制的圆圈:https://i.stack.imgur.com/3dY4q.jpg
我的代码:
import cv2
import numpy as np
img = cv2.imread('Photos/board.jpg')
output = img.copy()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# detect circles in the image
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.2, 100)
# ensure at least some circles were found
if circles is not None:
# convert the (x, y) coordinates and radius of the circles to integers
circles = np.round(circles[0, :]).astype("int")
# loop over the (x, y) coordinates …Run Code Online (Sandbox Code Playgroud) python ×6
anaconda ×1
animation ×1
detection ×1
graph ×1
indexing ×1
k-fold ×1
keras ×1
loss ×1
matplotlib ×1
mypy ×1
opencv ×1
pandas ×1
tensorflow ×1
typechecking ×1
ubuntu ×1
ubuntu-16.04 ×1