我的代码如下所示。
import numpy as np, pandas as pd, os
import matplotlib
import matplotlib.pyplot as plt
import itertools
from sklearn.metrics import confusion_matrix
import statsmodels.api as sm
import statsmodels.formula.api as smf
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import [![TruncatedSVD
from skle][1]][1]arn.preprocessing import Normalizer
import skfuzzy as fuzz
from sklearn import datasets
################################################################################
iris = datasets.load_iris()
x = pd.DataFrame(iris.data, columns=['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width'])
y = pd.DataFrame(iris.target, columns=['Target'])
scaler = StandardScaler()
X_std = scaler.fit_transform(x)
lsa = TruncatedSVD(2, algorithm = 'arpack')
dtm_lsa = lsa.fit_transform(X_std)
dtm_lsa = Normalizer(copy=False).fit_transform(dtm_lsa)
a= pd.DataFrame(dtm_lsa, columns = ["component_1","component_2"])
a['targets']=y
fig1, axes1 = plt.subplots(3, 3, figsize=(8, 8))
alldata = np.vstack((a['component_1'], a['component_2']))
fpcs = []
colors = ['b', 'orange', 'g', 'r', 'c', 'm', 'y', 'k', 'Brown', 'ForestGreen']
for ncenters, ax in enumerate(axes1.reshape(-1), 2):
cntr, u, u0, d, jm, p, fpc = fuzz.cluster.cmeans(
alldata, ncenters, 2, error=0.005, maxiter=1000, init=None)
# Store fpc values for later plots
fpcs.append(fpc)
# Plot assigned clusters, for each data point in training set
cluster_membership = np.argmax(u, axis=0)
for j in range(ncenters):
ax.plot(a['component_1'][cluster_membership == j],
a['component_2'][cluster_membership == j], '.', color=colors[j])
# Mark the center of each fuzzy cluster
for pt in cntr:
ax.plot(pt[0], pt[1], 'rs')
ax.set_title('Centers = {0}; FPC = {1:.2f}'.format(ncenters, fpc))
ax.axis('off')
fig1.tight_layout()
fig1.savefig('iris_dataset.png')
以下是我正在尝试的jquery
<input type="text" id="commentInput" >
<a class="Comment" data-toggle="modal" data-target="#commentModal"><i style="font-size: 30px;margin-left: 30px;" class="fa fa-comment-o" id="ficon" aria-hidden="true"></i></a>
但我没有得到var id = $('commentInput').closest('a').find('i').attr('id');
。它的投掷为id value
。
请提出任何建议。
答案 0 :(得分:3)
你有几个问题。首先,你错过了jQuery对象中id选择器的#
。其次,closest()
用于在元素的父元素处查找DOM。 a
是input
的兄弟,因此您可以使用next()
代替var id = $('#commentInput').next('a').find('i').prop('id');
console.log(id);
。试试这个:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="commentInput">
<a class="Comment" data-toggle="modal" data-target="#commentModal">
<i style="font-size: 30px;margin-left: 30px;" class="fa fa-comment-o" id="ficon" aria-hidden="true"></i>
</a>
//files to include
yourproject/sass/partials/_navbar.scss
yourproject/sass/partials/_footer.scss
//Main style.css
yourproject/sass/style.scss
@include "partials/navbar"
@include "partials/footer"