我正在尝试规范化我正在构建的数据库。一方面是我有许多不同的测试,每个测试都可以有许多不同的标签。你会如何处理这件事?
您是否有一个带有标签的表格,然后对每次测试的标签数量进行限制?
我是数据库的新手,更不用说规范化的整个想法了,所以如果这是一个非常简单的问题,请原谅我。
我试图在我的网站上实现类似于Facebook的"喜欢"功能的系统.用户可以点击按钮counter++的位置.但是,我在将数据有效存储到数据库方面遇到了问题.
每个故事都有在它自己排stories在我的数据库与列的表like和users_like.
我希望每个人只能一次喜欢这个故事.因此,我需要以某种方式存储数据,以显示用户实际上已经like++'发布了帖子.
我所能做的就是有一个名为users_like列的列CONCAT,然后使用php函数将每个用户(后跟逗号)添加到列中,然后使用php函数添加explode数据.
但是,据我所知,这种方法与数据库规范化的方向相反.
最好的方法是什么,我理解"最好"是主观的.
我不能liked在user桌子上添加一面旗帜,因为这个人可能会喜欢这么多故事.
谢谢
我想在 C++ 中实现Unicode 规范化,特别是 NFKC。为此,我需要一些任何语言(最好是 C++)的参考源代码。
或者您可以建议我如何开始实施。
问题在标题中,非常简单。
我有一个文件f,我正在从中读取一个ubyte数组:
arr = numpy.fromfile(f, '>u1', size * rows * cols).reshape((size, rows, cols))
max_value = 0xFF # max value of ubyte
Run Code Online (Sandbox Code Playgroud)
目前我正在 3 次重新规范化数据,如下所示:
arr = images.astype(float)
arr -= max_value / 2.0
arr /= max_value
Run Code Online (Sandbox Code Playgroud)
由于数组有点大,这需要明显的几分之一秒。
如果我能在 1 或 2 次数据传递中做到这一点,那就太好了,因为我认为这会更快。
有什么方法可以让我执行“复合”矢量操作来减少传递次数?
或者,有没有其他方法可以让我加快速度?
我有一个尺寸为 365x28(即 365 行和 28 列)的二维矩阵。我正在尝试使用以下代码对其进行规范化:
public static void main(String args[]) throws Exception {
double[][] X = new double [365][28];
double[][] X_min = new double [1][28];
double[][] X_max = new double [1][28];
double[][] X_norm = null;
X_norm = normalize(X, X_min, X_max);// error in this line
public static double[][] normalize(double[][] ip_matrix, double[][] min_bound, double[][] max_bound)
{
double[][] mat1 = ip_matrix;
double[][] norm = new double[mat1.length][mat1[0].length];
for (int i = 0; i < mat1.length; i++)
{
for (int j = 0; j …Run Code Online (Sandbox Code Playgroud) 我正在对一些数据进行kNN分类。我有按 80/20 的比例随机分割训练集和测试集的数据。我的数据如下所示:
[ [1.0, 1.52101, 13.64, 4.49, 1.1, 71.78, 0.06, 8.75, 0.0, 0.0, 1.0],
[2.0, 1.51761, 13.89, 3.6, 1.36, 72.73, 0.48, 7.83, 0.0, 0.0, 2.0],
[3.0, 1.51618, 13.53, 3.55, 1.54, 72.99, 0.39, 7.78, 0.0, 0.0, 3.0],
...
]
Run Code Online (Sandbox Code Playgroud)
矩阵最后一列中的项目是类:1.0、2.0 和 3.0特征标准化
后,我的数据如下所示:
[[-0.5036443480260487, -0.03450760227559746, 0.06723230162846759, 0.23028986544844693, -0.025324623254270005, 0.010553065215338569, 0.0015136367098358505, -0.11291235596166802, -0.05819669234942126, -0.12069793876044387, 1.0],
[-0.4989050339943617, -0.11566537753097901, 0.010637426608816412, 0.2175704556290625, 0.03073267976659575, 0.05764598316498372, -0.012976783512350588, -0.11815839520204152, -0.05819669234942126, -0.12069793876044387, 2.0],
...
]
Run Code Online (Sandbox Code Playgroud)
我用于标准化的公式:
(X - avg(X)) / (max(X) - min(X))
Run Code Online (Sandbox Code Playgroud)
我对K …
classification machine-learning normalization nearest-neighbor knn
我正在使用以下代码规范化熊猫数据框:
df_norm = (df - df.mean()) / (df.max() - df.min())
Run Code Online (Sandbox Code Playgroud)
当所有列都是数字时,这可以正常工作。但是,现在我有一些字符串列,df并且上面的规范化出现了错误。有没有一种方法只能在数据帧的数字列上执行这种规范化(保持字符串列不变)?谢谢!
我得到了一个图像 (32, 32, 3) 和两个表示均值和标准差的向量 (3,)。我正在尝试通过使图像进入可以减去均值并除以 std 的状态来标准化图像,但是当我尝试绘制它时出现以下错误。
ValueError: Floating point image RGB values must be in the 0..1 range.
Run Code Online (Sandbox Code Playgroud)
我理解错误,所以我想我在尝试规范化时没有执行正确的操作。下面是我尝试使用标准化图像的代码。
mean.shape #(3,)
std.shape #(3,)
sample.shape #(32,32,3)
# trying to unroll and by RGB channels
channel_1 = sample[:, :, 0].ravel()
channel_2 = sample[:, :, 1].ravel()
channel_3 = sample[:, :, 2].ravel()
# Putting the vectors together so I can try to normalize
rbg_matrix = np.column_stack((channel_1,channel_2,channel_3))
# Trying to normalize
rbg_matrix = rbg_matrix - mean
rbg_matrix = rbg_matrix / std
# Trying …Run Code Online (Sandbox Code Playgroud) 我有很多灰度图像要使用均值和标准差进行归一化。我使用以下过程:
计算图像的均值和标准差。
从图像中减去平均值。
将结果图像除以标准偏差。
但是,结果我得到了一个黑色图像。我的代码有什么问题?
import cv2
img = cv2.imread('E.png') # read an image
gray_image = cv2.cvtColor(img , cv2.COLOR_BGR2GRAY) # converting the image to grayscale image
img = cv2.resize(gray_image, (60, 60)) # Resize the image to the size 60x60 pixels
cv2.imwrite("Grayscale Image.png",img) #To write the result
mean, stdDev = cv2.meanStdDev(img) #Get Mean and Standard-deviation
image = (img-mean)/stdDev #Normalization process
cv2.imwrite("Normalized Image.png",image) #To write the result
Run Code Online (Sandbox Code Playgroud)
输入图像: 
灰度输出: 
归一化图像输出: 
我试图将单个特征归一化为 [0, 1],但我返回的结果是所有浮点值都为 1,这显然是错误的。
import pandas as pd
import numpy as np
from sklearn.preprocessing import normalize
test = pd.DataFrame(data=[7, 6, 5, 2, 9, 9, 7, 8, 6, 5], columns=['data'])
normalize(test['data'].values.reshape(-1, 1))
Run Code Online (Sandbox Code Playgroud)
这会产生以下输出:
array([[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.]])
Run Code Online (Sandbox Code Playgroud)
我认为这可能是一个 int to float 数据类型问题,所以我尝试首先转换为 float normalize(test['data'].astype(float).values.reshape(-1, 1)),但这给出了相同的结果。我错过了什么?